Professional Documents
Culture Documents
OUTLINE
1. OPERATOR
OPERATOR MATEMATIKA
()
+
-
*
/
OPERATOR LAINNYA....
%
++
--
=
Contoh:
2. LOOP
while(not a hundred times)
{
code
}
WHILE LOOP
while( condition )
commands;
while( condition )
{
Block of commands
}
Example 3-2 (example3-2.c)
#include<stdio.h>
main()
{
int i=0;
while( i<100 )
{
printf("\ni=%d",i);
i=i+1;
}
}
3. Tipe Konversi
hitung;
hitung = hitung+1;
Example3-2 (example3-2.c)
#include<stdio.h>
main()
{
int hitung=0;
float angka=0,jumlah=0,rerata=0;
printf("Enter score (-1 to stop): ");
scanf("%f",&angka);
while(angka>=0)
{
jumlah=jumlah+angka;
hitung++;
printf("Enter score (-1 to stop): ");
scanf("%f",&angka);
}
rerata=jumlah/hitung;
printf("\nRerata=%f",rerata);
printf("\nJumlah=%f\n",jumlah);
}
OUTPUT
#include<stdio.h>
main()
{
int i=0;
for(i=0;i<100;i++ )
printf("\ni=%d",i);
}
Example 3-4: example3-4.c
#include<stdio.h>
main()
{
int count=0;
float num=0,sum=0,avg=0;
for(count=0;count<7;count ++)
{
printf("Enter temperature : ");
scanf("%f",&num);
sum=sum+num;
}
avg=sum/7;
printf("\nAverage=%f\n",avg);
}
PR upload di https://forms.gle/rC4ynbefwoj4bFPs8
deadline 17 Des 2020 pukul 17:00