You are on page 1of 20

Kuliah Pengenalan Teknologi Informasi dan Pemrograman

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)

Input Cetak Cetak


score Jumlah Rata-rata
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

Enter score (-1 to stop): 12


Enter score (-1 to stop): 14
Enter score (-1 to stop): -1
Rerata=13.000000
Jumlah=26.000000
FOR LOOP

for( control statement )


command;
for( control statement )
block command;
Control Statement

for (initialization; test condition; run every time command)


Example 3-3 (example3-3.c)

#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

You might also like