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 variables num1, num2, and sum are declared to store user input and the sum of num1 and num2.

  • 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 variable num1.

  • 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 variable num2.

  • sum = num1 + num2;: Calculates the sum of num1 and num2 and stores the result in the variable sum.

  • printf("Sum of %d and %d is %d\n", num1, num2, sum);: Prints the sum of num1 and num2 using the printf function. %d is a placeholder for integers.

  • return 0;: Indicates successful termination of the main function and the program as a whole. It returns 0 to the operating system, indicating successful execution.