Write a c program to compute the the average of every third integer lying between 1 to 100 using while loop
Answers
Answered by
0
Program :
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
for(a=1,b=0,c=0;a<=100;a+=3)
{
c+=a;
b++;
}
printf("\n\tAverage of every third integer between 1 to 100 is %d",c/b);
getch();
}
Documentation :
Variable a is used for count 1 to 100variable c is sum of every third integer . get by a because a is incremented by 3 in each loop turn.Variable b is used to trace how many third number are in range of 1 to 100.As we know formula of calculating average is sum of value divided by number of element is perform while printing
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
for(a=1,b=0,c=0;a<=100;a+=3)
{
c+=a;
b++;
}
printf("\n\tAverage of every third integer between 1 to 100 is %d",c/b);
getch();
}
Documentation :
Variable a is used for count 1 to 100variable c is sum of every third integer . get by a because a is incremented by 3 in each loop turn.Variable b is used to trace how many third number are in range of 1 to 100.As we know formula of calculating average is sum of value divided by number of element is perform while printing
Answered by
0
Answer:
#include <stdio.h>
int main()
{
int i = 0;
static int sum = 0;
int j, x, k, avg;
while(i<=100){
i++;
j++;
if(j == 3){
printf("%d ", i);
j = 0;
sum += i;
k++;
}
}
printf("\nSum = %d", sum);
printf("\nNumber = %d", k);
printf("\nAverage = %d", sum/k);
scanf("%d", &x);
return 0;
}
Explanation:
Similar questions