I am trying to write a c program to read n numbers and reading of numbers should stop at the first occurence of odd numbers and find average of even numbers.
sample input:- 2,4,6,12,18,7
sample output:- 42
what i wrote is
Code:
#include<stdio.h>
int main()
{
int i,num,sum=0,cou;
float avg;
while(i>0)
{
printf("enter the integers");
scanf("%d",&num);
if(num%2!=0)
break;
else
printf("%d",num);
}
sum=sum+num;
cou++;
avg=sum/cou;
printf("average of given numbers is %f",avg);
return 0;
}
Can you please suggest what went wrong in the code ?