Archive for December, 2007

“Biner”

Posted in program Alant Junedi.DS on December 18, 2007 by 4l4nt

Input:

11001 1000001

Output:

11001 + 1000001:

Desimal : 25 + 65 = 90

Oktal : 31 + 101 = 132

Heksadesimal : 19 + 41 = 5A

________________________

| “Versi 1″ |

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>

void main()
{
char a[100],b[100],c[100],d[100];
long m,n,o;
int x,y,z;

while(scanf(“%s”,a)!=EOF){
scanf(“%s”,c);
clrscr();
printf(“%s + %s :\n”,a,c);
m=strtol(a,b,2);
n=strtol(c,d,2);
o=m+n;
printf(“Desimal : %d + %d = %d\n”,m,n,o);
printf(“Oktal : %o + %o = %o\n”,m,n,o);
printf(“Heksadesimal : %X + %X = %X\n”,m,n,o);
getch();
}
}

________________________

|”versi 2″|

#include <stdio.h>
#include <conio.h>
#include <math.h>
#include <string.h>
void main()
{
char a[10],b[10];
int c,d;
int e,f;
int i;
while(scanf(“%s%s”,&a,&b)!=EOF)
{
c = 0;
d = 0;
e = 0;
for(i=strlen(a);i>=0;i–)
{
if ( a[i] == ‘1′ ) c = c + (pow(2,e)/2);

e++;
}

e = 0;
for(i=strlen(b);i>=0;i–)
{
if ( b[i] == ‘1′ ) d = d + (pow(2,e)/2);
e++;
}
f = c + d;
printf(“%s + %s :\n”,a,b);
printf(“Decimal %d + %d = %d\n”,c,d,f);
printf(“Oktal %o + %o = %o\n”,c,d,f);
printf(“Hexadecimal %X + %X = %X\n”,c,d,f);
}
}

Reverse

Posted in program Alant Junedi.DS on December 17, 2007 by 4l4nt

Input:

12345

Output:

54321

________________________

#include <stdlib.h>
#include <stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
int number,i,x;
char string[25],l[25];
while(scanf(“%d”,&number)!=EOF){
itoa(number, string, 10);
i=strlen(string);

for(x=0;x<i;x++)
{
l[i-x-1]=string[x];
}

l[i]=string[i];
printf(“%s\n”,l);
}
getch();
}

“Transpose” (“,)

Posted in program Alant Junedi.DS on December 15, 2007 by 4l4nt

Input:

9

5

1

7

5

3

4

5

Output:

9 7 4

5 5 5

1 3 1

________________________

#include<stdio.h>
#include<conio.h>

void main(){
int i;
int angka[9];
while(scanf(“%d”,&angka[0])!=EOF) {
for(i=1;i<8;i++){
scanf(“%d”,&angka[i]);}

printf(“\n%d %d %d\n”,angka[0],angka[3],angka[6]);
printf(“%d %d %d\n”,angka[1],angka[4],angka[7]);
printf(“%d %d %d\n”,angka[2],angka[5],angka[8]);
getch();
}
}

“Ketupat”

Posted in program Alant Junedi.DS on December 15, 2007 by 4l4nt

#include<stdio.h>

void bk(int n) {
int i,j;
for(i=0;i<n+1;i++){
for(j=n;j>i;j–){
printf(” “);}
for(j=1;j<=(2*i+1);j++){
if(j%2==0){ printf(” “);}
if(j%2==1){ printf(“*”);}}
printf(“\n”);}
for(i=0;i<n;i++){
for(j=-1;j<i;j++){
printf(” “);}

for(j=(2*n)+1;j>(2*i)+1;j–){
if(j%2==0){ printf(” “);}
if(j%2==1){ printf(“*”);}}
printf(“\n”);}}
void main() {
int angka,x[6];
while(scanf(“%d”,&angka)!=EOF) {
if(angka >=1 && angka<=1000000) {

do{
x[5]=angka/100000;
x[4]=(angka-(x[5]*100000))/10000;
x[3]=(angka-(x[4]*10000)-(x[5]*100000))/1000;
x[2]=(angka-(x[3]*1000)-(x[4]*10000)-(x[5]*100000))/100;
x[1]=(angka-(x[2]*100)-(x[3]*1000)-(x[4]*10000)-(x[5]*100000))/10;
x[0]=angka%10; angka=x[0]+x[1]+x[2]+x[3]+x[4]+x[5]; }
while(angka>=10);
bk(angka); }}}

Manipulasi String :-P

Posted in program Alant Junedi.DS on December 15, 2007 by 4l4nt

Input:

alant junedi ds

Output:

ALANT JUNEDI DS

alant junedi ds

AlAnT JuNeDi dS

aLaNt jUnEdI Ds

________________________

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<ctype.h>

void main() {
char kalimat[100];
int i;
clrscr();
gets(kalimat);
printf(“%s\n”, strupr(kalimat));
printf(“%s\n”, strlwr(kalimat));
for(i=0; i<strlen(kalimat); i++) {
if(i%2!=0 && kalimat[i]!=NULL) printf(“%c”, tolower(kalimat[i]));
else printf(“%c”, toupper(kalimat[i]));
}
printf(“\n”);
for(i=0; i<strlen(kalimat); i++) {
if(i%2==0) printf(“%c”, tolower(kalimat[i]));
else printf(“%c”, toupper(kalimat[i]));
}
printf(“\n”);
getch();
}

Deret ganjil dan genap dari suatu angka

Posted in program Alant Junedi.DS on December 15, 2007 by 4l4nt

Input:

10

Output:

genap   : 0 2 4 6 8 10

ganjil    : 1 3 5 7 9

________________________

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;

while(scanf(“%d”,&b)!=EOF)
{
printf(“Genap :”);
for(a=0;a<=b;a++)
{
if(a%2==0)printf(” %d”,a);
}
printf(“\nGanjil :”);
for(c=0;c<=b;c++)
{
if(c%2!=0)printf(” %d”,c);
}
printf(“\n”);
}
}

“ganjil 3n+1, genap n/2″

Posted in program Alant Junedi.DS on December 14, 2007 by 4l4nt

input:

5

8

9

output:

jumlah 3n+1 dari 5

5 16 8 4 2 1

jumlah 3n+1 dari 8

8 4 2 1

jumlah 3n+1 dari 9

9 28 14 7 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1

_________________________

#include <conio.h>
#include <stdio.h>

void main ()
{

int a,b,c;
scanf(“%d”,&a);
scanf(“%d”,&b);
scanf(“%d”,&c);
printf(“jumlah 3n+1 dari %d\n”,a);
printf(“%d”,a);

do{
if (a%2!=0){
a = 3*a+1;
}
else if(a%2==0){
a= a/2;
}
printf(” %d”,a);
}while (a!=1);

printf(“\n”);
printf(“jumlah 3n+1 dari %d\n”,b);
printf(“%d”,b);

do {
if (b%2!=0){
b = 3*b+1;
}
else if(b%2==0){
b= b/2;
}
printf(” %d”,b);
} while (b!=1);

printf(“\n”);
printf(“jumlah 3n+1 dari %d\n”,c);
printf(“%d”,c);

do {
if (c%2!=0){
c = 3*c+1;
}
else if(c%2==0){
c= c/2;
}
printf(” %d”,c);
} while (c!=1);

getch();

}

Tanda panah

Posted in program Alant Junedi.DS on December 14, 2007 by 4l4nt

input:

masukkan=5

output:

*****

**

* *

* *

* *

_________________________

#include<stdio.h>
#include<conio.h>

void main()
{
int a,b,c,d,e;
printf(“input masukan=”);
scanf(“%d”,&a);

d=2;
e=1;

for(b=1;b<=a;b++)
{
printf(“*”);
}
printf(“\n”);

for(b=1;b<a;b++)
{
for(c=1;c<=a;c++)
{
if(c==d || c==e)
{
printf(“*”);
}
else printf(” “);
}
printf(“\n”);

d=d+1;
}

getch();
}

“Kalkulator cupu alant junedi”

Posted in program Alant Junedi.DS on December 14, 2007 by 4l4nt

#include <stdio.h>
#include <conio.h>
#include <string.h>

void hapus (){
clrscr ();
}

void main (){
int umur;
int tambah1, tambah2, hasiltambah;
int kali1, kali2, hasilkali;
int tekan;
char nama [20];

hapus();
printf (“                       kalkulator cupu ala alant junedi\n”);
do {
gotoxy(1,4);
printf (“masukkan nama anda : “);
clreol (); fflush (stdin);
gets (nama);
} while (strlen (nama) >150);
do {
gotoxy(1,5);
printf (“masukkan umur anda [17+]: “);
clreol ();
fflush (stdin);
scanf (“%d”, &umur);
} while ( umur < 17 );
hapus();

do {
hapus();
gotoxy (1,2);
printf (” selamat datang %s”, nama);
gotoxy (1,3);
printf (” umur : %d “, umur);
gotoxy (1,5);
printf (“PILIH MENU : “);
gotoxy (1,6);
printf (“1. penjumlahan”);
gotoxy (1,7); printf (“2. perkalian”);
gotoxy (1,8); printf (“3. exit”);

tekan=getch();
switch (tekan) {
case ‘1′ : hapus();
gotoxy (2,2);
printf (“masukkan angka pertama = “); scanf (“%d”, &tambah1);
gotoxy (2,3);
printf (“kalo angka kedua = “); scanf (“%d”, &tambah2);
hasiltambah = tambah1 + tambah2;
gotoxy (2,4);
printf (“hasil = %d “, hasiltambah);
getch ();
break;
case ‘2′ : hapus();
gotoxy (2,2);
printf (“masukkan angka pertama = “); scanf (“%d”, &kali1);
gotoxy (2,3);
printf (“masukkan angka kedua = “); scanf (“%d”, &kali2);
gotoxy (2,4);
hasilkali = kali1 * kali2;
printf (“hasil = %d “, hasilkali);
getch();
break; }

} while (tekan !=1 || tekan !=2);
getch();
}

Gabungan segitiga dan kubus

Posted in program Alant Junedi.DS on December 14, 2007 by 4l4nt

input:

5

output:

*

* *

* * *

* * * *

* * * * *

(Space)

* * * * *

* * * * *

* * * * *

* * * * *

* * * * *

________________________

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main(){

int i,j;
int angka;

scanf (“%d”, &angka);
clrscr();

for ( i=1; i<=angka; i++){
for ( j=1; j<=i; j++){
printf (“* “);
}
printf (“\n”);
}
printf(“\n”);

for ( i=1; i<=angka; i++){
for ( j=1; j<=angka; j++){
printf (“* “);
}
printf (“\n”);
}
getch();
}