Write a program that calculates the sum of four numbers of type int entered on the keyboard,
- using 5 variables (saving of the entered values)
- using 2 variables (loss of the entered values)
Difficulty level

Video recording
This exercise is mostly suitable for students
#include <stdio.h>
int main()
{
int a, b, c, d, sum;
printf("Enter 4 integer variables: ");
scanf("%d %d %d %d",&a, &b, &c, &d);
sum = a + b + c + d;
printf("%d + %d + %d + %d = %d\n", a, b ,c ,d, sum);
return 0;
}
#include <stdio.h>
int main()
{
int a, sum;
printf("Enter an integer: ");
scanf("%d",&a);
sum = a;
printf("Enter a second integer: ");
scanf("%d",&a);
sum = sum + a;
printf("Enter a third integer: ");
scanf("%d",&a);
sum = sum + a;
printf("Enter a fourth integer: ");
scanf("%d",&a);
sum = sum + a;
printf("Sum = %d\n", sum);
return 0;
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
