C program to find sum of two numbers

Here is the c program to find sum of two numbers

#include<stdio.h>

int main()
{
   int a, b, c;
   printf("Enter two numbers: ");
   scanf("%d%d", &a, &b);
   c = a + b;
   printf("The sum is: %d\n", c);
   return 0;
}

Output

Enter two numbers: 5 4
The sum is: 9

Explanation:

printf("The sum is: %d\n", c); prints the sum with a newline character for better output formatting.

main Function: In C programming, the main function should always return an integer (int). This integer typically indicates the success or failure of the program (usually 0 for success).

Input and Output:

printf("Enter two numbers: "); prompts the user to enter two integers.

scanf("%d%d", &a, &b); reads two integers from the user input.

c = a + b; calculates the sum of a and b.

Naveed Tawargeri
 

Hi, I'm Naveed Tawargeri, and I'm the owner and creator of this blog. I'm a Software Developer with a passion for Programming.