Pages

This blog is under construction

Sunday, January 6, 2019

Write a program to compute and display the sum of all integers that are divisible by 6 but not divisible by 4 and lie between 0 and 100. The program should also count and display the number of such values (use of goto statement)

C Code:

#include<stdio.h>
void main()
{
  int Sum,i,Count;
  Sum=Count=0;
  i=0;  
 Loop:
 if((i%6==0)&&(i%4!=0))
 {
  printf("%d \n",i);
 Count=Count+1;
 Sum=Sum+i;
 }
  i=i+1;
  if(i<=100)
  goto Loop;
  printf("Sum of Numbers is %d\n",Sum);
  printf("Count of Numbers is %d\n",Count);
 }

Output:


6                                                                                                                        
18                                                                                                                             
30                                                                                                                             
42                                                                                                                             
54                                                                                                                             
66                                                                                                                             
78                                                                                                                             
90                                                                                                                             
Sum of Numbers is 384                                                                                                          
Count of Numbers is 8 

No comments:

Post a Comment