selamat <isi sendiri> guys
fungsi control statement adalah statement yang digunakan untuk mengarahkan jalnnya program, sehingga urutan pengerjaan program dapat melompat – lompat atau berulang. Ada beberapa statement yang termasuk control statement yaitu statements if – else, else – if, go to (), switch (), break, continue, for (), while (), dan do while
PROGRAM MATRIKS
#include <stdio.h>
main()
{
int x,y,z,p,q,r;
for(x=1;x<=5;x++)
{
for(y=1;y<=5;y++)
{
if(x==y)
printf (” 1 “);
else
printf(” 0 “);
}
y =1;printf(“\n”);
}
getch ();
}
PROGRAM TABEL PERKALIAN
#include <stdio.h>
main()
{
int x,y,z,p,q,r;
for(x=1;x<=5;x++)
{
for(y=1;y<=5;y++)
{
if(x==y)
printf (” 1 “);
else
printf(” 0 “);
}
y =1;printf(“\n”);
}
getch ();
}
contoh program :
PROGRAM BILANGAN BULAT
void main ()
{
int x ;
printf( “Masukkan data bilangan bulat = “);
scanf (“%d” ,&x);
while(x>0)
{
printf (“%d”, x%10 );
x = x/10;
}
getch();
}
PROGRAM KONVERSI SUHU
{
float z=10;
int x,y;
printf(“Masukan jumlah larik tabel = “);
scanf (“%d”, &x);
printf(“\n NO FARENHEIT REAMUR KELVIN”);
for(y = 1; y <= x; y++)
{
printf(“\n%2d”,y);
printf(“%-7g”,z);
z = (z-32)*4/9;
printf (“%-9g”,z);
z = (z*5/4)+273;
printf (“%6g”,z);
z -= 273;
z += 10;
}
getch();
}
PROGRAM NILAI RATA – RATA
void main()
{
int x,y,z,p = 0;
printf (“Masukkan nominal nilai 0 =”);
scanf (“%d”, &x);
for (y=1;y<=x;y++)
{
printf (“Masukkan nominal nilai %d = “, y);
scanf (“%d”, &z);p+=z;
}
printf (“Jumlah seluruh nilai adalah = %d\n”,p);
p = p/x;
printf (“nilai rata – rata = %d”,p);
getch();
}
PROGRAM KALKULATOR
void main ()
{
int x,y,z,p,q,r;
char e;
mulai:
printf (“\n Masukkan angka positif = “);
scanf (“%1d%1d%1d%1d”, &x, &y, &z, &p);
f = x + y + z + p;
printf (“\n Jumlah angka %d%d%d%d adalah %d+%d+%d+%d = %6d”, x,y,z,p,x,y,z,p,r);
printf (“\n Coba lagi ? (y/n)”);
getchar();
scanf (“%c”, &e);
if (e==’y’)
{
goto mulai;
}
getch ();
}
PROGRAM FAKTORIAL
void gotoxy(int x ,int y);
int main ()
{
int a,b,c,d;
printf (“Masukkan jumlah tabel faktorial “);
scanf (“%d”,&d);
printf (“NOMER HASIL FAKTORIAL”);
for (a = 1; a<=d;a++)
{
c = 1;
printf (“\n%2d %2d!”,a,a);
for (b=a;b>0;b–)
{
printf (“%-d”,b);c*=b;
if (b!=1){printf(“x”);}
}
printf (” = %d”,c);
}
getch ();
}
PROGRAM NILA MAKSIMUM NILAI MINIMUM
void main ()
{
float a,b,c,d = 0, z = 0, x = 0;
printf(“Masukkan banyaknya data nilai = “);
scanf(“%f”, &a);
for (b = 1; b <=a; b++)
{
printf (” masukkan nilai “, b);
scanf (“%g”, &c);d+=c;
if(x==0)
x = c;
if(z<=c)
z=c;
if(x>=c)
x=c;
}
printf (“\n Nilai minimum = %g”,x);
printf (“\n Nilai maksimum = %g”,z);
d=d/a;
printf (“\n nilai rata – rata = %g”, d);
getch();
}
Recent Comments