In: Computer Science
Create a program that asks the user to input three numbers and computes their sum. This sounds simple, but there's a constraint. You should only use two variables and use combined statements. You can use the output below as a guide. Please enter the first number: 4 Please enter the second number: 2 Please enter the third number: 9 The sum of the three numbers is: 15.
#include <stdio.h>
int main() {
int n1, n2, n3;
/**
* printf is used to print stuff onto the screen
* scanf is used to read values/numbers from the user
*/
printf("Please enter the first number: "); // ask user to enter first number
scanf("%d", &n1); // read first number into variable n1
printf("Please enter the second number: "); // ask user to enter second number
scanf("%d", &n2); // read second number into variable n2
printf("Please enter the third number: "); // ask user to enter third number
scanf("%d", &n3); // read third number into variable n3
printf("The sum of the three numbers is: %d.\n", n1+n2+n3); // calculate the sum and display the sum to the user
return 0;
}
