Calculations

C program to the sum of two numbers

C program to the sum of two numbers

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

Sum of two integer

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

 

Sum of two integer- get user input

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

Operator in C language

Python program to sum of two numbers
Java program to multiply two numbers
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

1 month ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago