Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Write a program of addition of number in c PROGRAM

Here’s an example of a C program that calculates the sum of two numbers:

 
#include <stdio.h>
 
int main() {
    int num1, num2, sum;
 
    printf(“Enter the first number: “);
    scanf(“%d”, &num1);
 
    printf(“Enter the second number: “);
    scanf(“%d”, &num2);
 
    sum = num1 + num2;
 
    printf(“The sum of %d and %d is %d.\n”, num1, num2, sum);
 
    return 0;
}
 

Output;

Enter the first number: 2
Enter the second number: 3
The sum of 2 and 3 is 5.
 
 
 
 

in this program, we declare three variables: num1, num2, and sum. The user is prompted to enter the first number, which is stored in num1. Then, the user is prompted to enter the second number, which is stored in num2. The sum of num1 and num2 is calculated and stored in the sum variable. Finally, the program outputs the result using printf

addition of two number in c

Here are some keywords used in the code:

#include: This is a preprocessor directive that tells the compiler to include the contents of the specified header file (stdio.h) in the program.


int: This keyword is used to define integer variables. In this code, num1, num2, and sum are declared as int variables.


main: It is the entry point of the program. The execution of the program starts from here.


printf: This function is used to print formatted output to the console. It is used to display messages to the user.


scanf: This function is used to read input from the user. It allows the program to receive values for num1 and num2 from the user.


return: The return statement is used to terminate the main function and return a value to the calling environment. In this case, return 0 indicates that the program has executed successfully.

These keywords are essential elements of the C programming language and are commonly used in various programs.

1 thought on “Write a program of addition of number in c PROGRAM”

Leave a Comment