In this tutorial, we will discuss the C program to the sum of two numbers.
In this topic, we will learn how to find the sum of two integer number in C language
Program 1
#include <stdio.h> #include <stdlib.h> int main() { int num_1=56,num_2=34,sum; //value already assigned sum=num_1+num_2;//calculate sum printf("\sum of these numbers: %d ",sum);//display sum value getch(); return 0; }
When the above code is compiled and executed, it produces the following results
sum of these numbers: 90
Program 2
#include <stdio.h> #include <stdlib.h> int main() { int num_1,num_2,sum;//declared variable printf("\Enter two integer value: "); scanf("%d %d",&num_1,&num_2); //call the scanf() function to store values entered by user sum=num_1+num_2; //calculate sum of two numbers in stored in variable sum printf("%d + %d =%d:",num_1,num_2,sum);//display sum of numbers getch(); return 0; }
When the above code is compiled and executed, it produces the following results
Enter two integer value: 45 65 45 + 65 = 110
In the above program, the user is entered two integer point value for find sum.
we use the pre-defined function scanf() for getting value from the user. So two integer values entered by the user and it is stored in variables num_1 and num_2
Then, te variables num_1 and num_2 are added using plus(+) operator and then the result displaying on the screen using printf() function
Suggested for you
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…