In our day-to-day life, we do calculations like addition, subtraction, multiplication, and division on numbers such as integers, real numbers, whole numbers, etc.

We perform such arithmetic operations in the C programming language using our c programs.

This article by Simplilearn will help you understand how to execute the addition of two numbers programs in detail.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

How to Execute the Addition of Two Integer Numbers Program?

Using the addition operator(+), we will perform addition operations on two operands. From the following code, a and b are the operands, and the sum is the variable. Once the addition is performed, the result is stored in the variable sum and displayed as an output. 

Now you know the logic of a program. Let's have a look at the program code.

#include <stdio.h>

int main()

{

    int a=10, b=5, sum;

    sum=10+5;

    printf("The addition of %d and %d is: %d",a,b,sum);

    return 0;

}

Output:

Addition_Program_in_C_1.

Look at the below-given diagram to understand it in a better way.

Addition_Program_in_C_2

The values of a and b are 10 and 5, respectively. By adding 10+5, the output stored in the sum variable is 15.

Now, let's execute another program to perform the addition of two numbers by taking inputs from the user.

#include <stdio.h>

int main()

{

    int a;

    float b,sum;

    printf("Enter two values for a and b");

    scanf("%d %f",&a,&b);

    sum=a+b;

    printf("Addition of two numbers %d and %f is: %f",a,b,sum);

    return 0;

}

Output:

Addition_Program_in_C_3

From the above code, we are asking the user to enter the values for the variable a of type int and b of type float using scanf(). And the values entered for a and b are 2 and 4.6, respectively. Using printf(), we are printing the result 6.600000 floating value as an output.

Want a Top Software Development Job? Start Here!

Full Stack Developer - MERN StackExplore Program
Want a Top Software Development Job? Start Here!

Addition of Two Integer Numbers Using Function in C

The logic of a C program is easy to understand, and the whole C program can be divided into individual and functional units. It means every function in the program acts as an independent unit to perform a specific task or an operation and is also capable of running separately.

The below code has a function with an argument that performs the addition operation. And in the main function, there is a function call, and the result is printed. 

#include<stdio.h>

int sum(int a, int b)

{

 int c;

 c=a+b;

 return(c);

}

main()

{

int a,b,result;

printf("Enter two numbers for a and b\n");

scanf("%d %d",&a,&b);

result=sum(a,b);

printf("Addition of two numbers is:%d",result);

}

Output:

Addition_Program_in_C_4.

With that, you can conclude this tutorial on how to execute the addition program in C. 

If you're eager to gain the skills required to work in a challenging, rewarding, and dynamic IT role - we've got your back! Discover the endless opportunities through this innovative Post Graduate Program in Full Stack Web Development course designed by our partners at Caltech CTME. Enroll today!

Next Steps

"Data Structures in C" can be your next topic. So far, you have learned the addition program in C. The next fundamentals will be the data structures and the varieties in data structures used for different purposes.

If you are interested in building a career in software development, then feel free to explore Simplilearn's Courses that will give you the work-ready software development training you need to succeed today. Are you perhaps looking for a more comprehensive training program in the most in-demand software development skills, tools, and languages today? If yes, our Post Graduate Program in Full Stack Web Development should be the right thing for your career. Explore the course and enroll soon.

Please let us know in the comment section below if you have any questions regarding the "Addition Program in C ” tutorial. Our experts will get back to you at the earliest.

Our Software Development Courses Duration And Fees

Software Development Course typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Caltech Coding Bootcamp

Cohort Starts: 16 Dec, 2024

6 Months$ 8,000
Automation Test Engineer Masters Program

Cohort Starts: 27 Nov, 2024

8 months$ 1,499
Full Stack Java Developer Masters Program

Cohort Starts: 18 Dec, 2024

7 months$ 1,449
Full Stack (MERN Stack) Developer Masters Program

Cohort Starts: 8 Jan, 2025

6 Months$ 1,449