/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE?
QUESTION: This program reads integers from standard
input. The first
integer indicates the number of values that will follow.
Read that many values, and return their sum, ignoring any
additional values that may follow. However, if there
are
fewer integers than specified in the input, print "Error"
and terminate.
Hint:
int n, success;
...
success = scanf("%d", &n); // FIRST INTEGER INPUT
reads an integer from stdin, returning 1 if the integer
was successfully read.
*/
#include <stdio.h>
main()
{
int count;
int success;
int n;
int sum;
int i;
sum = 0;
scanf("%d", &n);
for(i = 0; i < n; ++i){
success = scanf("%d", &count);
sum = sum + count;
}
printf("%d\n", sum);
}
Code:
#include<stdio.h>
int main()
{
int n, i=0, num, input=0,success;
int count=0, value;
int sum = 0;
printf("Enter the Total Number of integer Values: ");
scanf("%d",&n);
printf("Enter %d integer values: ",n);
for(i=0;i<n;i++)
{
success = scanf("%d",&value);
printf("\nsuccess = %d\n",success);
sum = sum+value;
}
printf("The sum of %d integers are %d\n", n, sum);
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.