#include<stdio.h>
#include<conio.h>
main()
{
int i,bil1,bil2,n;
float rata_rata,total;
printf("Masukkan 2 buah bilangan:\n");
printf("Bilangan 1= ");
scanf("\n %d", &bil1);
printf("\nBilangan 2= ");
scanf("\n %d", &bil2);
total=0;
n=0;
if (bil1<bil2)
{
for(i=bil1;i<=bil2;i++)
{
printf("\n%d",i);
total+=i;
n++;
}
}
else if (bil1>bil2)
{
for(i=bil1;i>=bil2;i--)
{
printf("\n%d",i);
total+=i;
n++;
}
}
else {
printf("%d",bil2);
total=bil1;
n=1;
}
printf("\ntotal = %.0f\n",total);
printf("rata_rata: %.1f",total/n);
getche();
}
Selasa, 20 September 2011
Mencari rata-rata dengan pengulangan FOR
OUTPUT:
0 comments:
Posting Komentar