Write a program which reads a sequence of positive integer values and shows their multiplication and their sum when the user fills a negative number.
Difficulty level
This exercise is mostly suitable for students
#include<stdio.h>
#include<limits.h>
int main()
{
int N, mult, sum;
mult = 1;
sum = 0;
while(1)
{
printf("Enter an integer: ");
scanf("%d", &N);
if(N<0)
break;
mult*=N;
sum+=N;
}
printf("Sum = %d\tMult=%d\n",sum,mult);
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Level with maximum sum in binary trees