EmbLogic's Blog

Program that reads until 0 is entered & reports even , odd integers & their averages.

#include
2 int main()
3 {
4 int num=0,evn=0,odd=0,even_sum=0,odd_sum=0;
5
6
7 for(;;)
8 {
9 printf(“enter the numbers\n”);
10 scanf(“%d”, &num);
11
12 if(num==0)
13 {
14 break;
15 }
16
17 else if(num%2==0)
18 {
19 evn++;
20 even_sum+= num;
21 }
22
23 else if(num%2!=0)
{
25 odd++;
26 odd_sum+=num;
27 }
28 }
29
30 printf(“the total no. of even numbers is %d\n”, evn);
31 printf(“the total no. of odd numbers is %d\n”, odd);
32 printf(“\neven Sum:%d”,even_sum);
33 printf(“\nodd sum:%d\n”,odd_sum);
34 printf(“the average of evn numbers is %d\n”,(int)(even_sum/evn));
35 printf(“the average of odd numbers is %d\n”, (int)(odd_sum/odd));
36
37 return 0;
38 }
39 p

1,4 Top

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>