Wednesday, 23 April 2014

3. Design a Flowchart: and write an interactive program that reads in integers until a 0 is entered. If it encounters 0 as input, then it should display: .the total number of even and odd integers .average value of even integers .Average value of odd integers. . Note: Use switch statement for selection



#include<stdio.h>
#include<conio.h>
void main()
{
          int val,even=0,odd=0,sum_even=0,sum_odd=0,avg_even,avg_odd;
          clrscr();
          first:
                             printf("\n\n\t\tEnter value -> ");
                             scanf("%d",&val);
                             if(val==0)
                             {
                                      goto last;
                             }
                             else if(val%2==0)
                             {
                                      even++;
                                      sum_even=sum_even+val;
                                      goto first;
                             }
                             else
                             {
                                      odd++;
                                      sum_odd=sum_odd+val;
                                      goto first;
                             }
          last:
                   avg_even=sum_even/even;
                   avg_odd=sum_odd/odd;
                   printf("\n\n\t\tYour Total Even No is %d",even);
                   printf("\n\n\t\tYour Total Odd No. is %d",odd);
                   printf("\n\n\t\tYour Avg value of Even is %d",avg_even);
                   printf("\n\n\t\tYour Avg value of Odd is %d",avg_odd);
          getch();
}

No comments:

Post a Comment