Given a set of 10 two-digit integers containing both positive and negative values, write a program using for loop to compute the sum of all positive values and print the sum and the number of values added. The program should use scanf to read the values and terminate when the sum exceeds 999. Do not use goto statement.
#include <stdio.h>
void main()
{
int x,i,sum=0,count=0;
clrscr();
printf("Enter 10 two-digit integer number\n");
for(i=1;i<=10;i++)
{
scanf("%d",&x);
if(x>0)
{
count++;
sum+=x;
if(sum>999)
break;
}
}
printf("%d numbers are added and result = %d",count,sum);
getch();
}
#include <stdio.h>
void main()
{
int x,i,sum=0,count=0;
clrscr();
printf("Enter 10 two-digit integer number\n");
for(i=1;i<=10;i++)
{
scanf("%d",&x);
if(x>0)
{
count++;
sum+=x;
if(sum>999)
break;
}
}
printf("%d numbers are added and result = %d",count,sum);
getch();
}
No comments:
Post a Comment