addition of two numbers in C ?


Q.) program to add two no. in C ?
 #include<stdio.h>
 #include<conio.h>
 int main()
 {
	 int a=10,b=20,sum;
     sum = a + b; 
     printf("Sum of two numbers :%d",sum);
     getch();
 }
Output
Sum of two numbers :30

Program Explanation


Step 1: Include header files (#include<stdio.h> and #include<conio.h>).

Step 2: Start with main function with return type.

Step 3: parenthesis to start and end the program { }.

Step 4: declare the variables with data types. i.e, values of 'a' and 'b' are of integer type, so we declare 'a' and 'b' variable with "int" data type. We also declare 'sum' as int variable because it returns an integer value.

Step 5: Use output function printf() to print the output on the screen.

Step 6: using getch() function to hold the screen.