california
#include <stdio.h>
int main() {
int num1, num2, sum;
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);
sum = num1 + num2;
printf("Sum of %d and %d is %d\n", num1, num2, sum);
return 0;
}
Explanation:
#include <stdio.h>
: Includes the standard input-output library in C, allowing for input/output operations.int main() { ... }
: The main function of the program where execution begins. It returns an integer.int num1, num2, sum;
: Declaration of three integer variablesnum1
,num2
, andsum
without assigning any values.printf("Enter first number: ");
: Displays a message prompting the user to enter the first number.scanf("%d", &num1);
: Reads an integer input from the user and stores it in the variablenum1
.printf("Enter second number: ");
: Displays a message prompting the user to enter the second number.scanf("%d", &num2);
: Reads an integer input from the user and stores it in the variablenum2
.sum = num1 + num2;
: Calculates the sum ofnum1
andnum2
and assigns the result to the variablesum
.printf("Sum of %d and %d is %d\n", num1, num2, sum);
: Prints the sum ofnum1
andnum2
using theprintf
function with format specifiers%d
for integers.return 0;
: Indicates the successful termination of themain()
function with a return value of 0, indicating the program ran without errors.