user define
#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>
: This line includes the standard input-output header file in the program, allowing the use of input and output functions.int main() { }
: This is the main function where the execution of the program begins and contains the code to be executed.int num1, num2, sum;
: Three integer variablesnum1
,num2
, andsum
are declared to store user input and the sum ofnum1
andnum2
.printf("Enter first number: ");
: This prints a message to prompt the user to enter the first number.scanf("%d", &num1);
: Reads an integer value entered by the user and stores it in the variablenum1
.printf("Enter second number: ");
: This line prompts the user to enter the second number.scanf("%d", &num2);
: Reads an integer value entered by the user and stores it in the variablenum2
.sum = num1 + num2;
: Calculates the sum ofnum1
andnum2
and stores the result in the variablesum
.printf("Sum of %d and %d is %d\n", num1, num2, sum);
: Prints the sum ofnum1
andnum2
using theprintf
function.%d
is a placeholder for integers.return 0;
: Indicates successful termination of themain
function and the program as a whole. It returns 0 to the operating system, indicating successful execution.