Rabu, 26 November 2008

Program konversi suhu

Source Code

#include
#include
void main()
{
int pilihan;
char lanjut;
float celcius,fahrenhait,reamur;
do
{
printf("\n ~Selamat Datang pada Program Percabangan~ \n");

printf("\n *Silahkan Pilih Menu Yang Anda Inginkan* \n");
printf("\n");

printf("========================M E N U============================");
printf("\n");
printf("\n");
printf("1. Konversi Celcius Ke Fahrenheit\n");
printf("2. Konversi Fahrenheit Ke Celcius\n");
printf("3. Konversi Celcius Ke Reamur\n");
printf("4. Konversi Reamur Ke Celcius\n");
printf("5. Konversi Fahrenheit Ke Reamur\n");
printf("6. Konversi Reamur Ke Fahrenhait\n");
printf("\n");
printf("\n");
printf("pilih menu (1, 2, 3, 4, 5, 6)?");
scanf("%d",&pilihan);
printf("\n");
switch (pilihan)
{
case 6:
printf("suhu reamur?");
scanf("%f",&reamur);
printf("Jadi,fahrenhait=%.2f\n",2.25*reamur+32);
break;
case 5:
printf("suhu fahrehait?");
scanf("%f",&fahrenhait);
printf("Jadi,reamur=%.2f\n",0.445*(fahrenhait-32));
break;
case 4:
printf("suhu reamur?");
scanf("%f",&reamur);
printf("Jadi,celcius=%.2f\n",1.25*reamur);
break;
case 3:
printf("suhu celcius?");
scanf("%f",&celcius);
printf("Jadi,reamur=%.2f\n",0.8*celcius);
break;
case 2:
printf("suhu fahrehait?");
scanf("%f",&fahrenhait);
printf("Jadi,celcius=%.2f\n",0.556*(fahrenhait-32));
break;
case 1:
printf("suhu celcius?");
scanf("%f",&celcius);
printf("Jadi,fahrenhait=%.2f\n",(1.8*celcius)+32);
break;
}
printf("\n");
printf("apakah anda ingin mengulang (y/t): ");
lanjut=getche();
printf("\n");
}
while(lanjut=='y'||lanjut=='Y');
getch();
}

Output

Program membuat program segitiga bintang

Source code
#include
void main()
{
int n, a, c=0, z, x, y;
printf("-------------------------------\n");
printf(" PROGRAM SEGITIGA BINTANG \n");
printf("-------------------------------\n");

printf("Inputkan jumlah baris : ");
scanf("%d",&n);
puts("");
a=n;
z=n-1;

for(x=1;x<=n;x++) { c=1; for(y=1;y<=a;y++) { if (c<=z) { printf(" "); c=c++; } else { if(y==c||y==a||z==0) printf(" *"); else printf(" "); } } z=z--; a=a++; printf("\n"); } }

Output