Question
/*C PROGRAMMING: HOW TO INSERT ERROR BELOW CODE? QUESTION: This program reads integers from standard input . The first integer indicates the number of values
/*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
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 ", sum); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started