addition

C program to add two numbers using function

C program to add two numbers using the function

In this tutorial, we will learn C program to add two numbers using the function

In this topic, we will learn a simple concept of how to add two number using the function in C programming language

already we know the same concept using the operator in a simple way.

if you knew click here C program to the sum of two numbers

This program has following procedures to completion

  1. Function declaration or prototype
  2. Ask input from the user for values
  3. Define the function
  4. Call the function
  5. Display result on the screen

 

Program 1

#include <stdio.h>
#include <stdlib.h>
int sum(int , int);//function declaration or prototype
int main()
{
    int num1,num2,total;//variable declaration
    printf("Enter the two number ");
    scanf("%d %d",&num1,&num2);//getting two number as input from user
    total=sum(num1,num2);//calling the function
    //The total value (returned by the function) is stored in total variable.
    printf("The sum of these numbers :%d",total);
    //display the total value
    getch();
    return 0;
}
int sum(int a, int b)//defining function based in declaration
{
    int result=a+b;//find sum of two numbers
    //and result of sum stored in result variable
    return result;//returning result
}

When the above code is compiled and executed, it produces the following results

Enter the two numbers 45
75
The sum of these numbers :120

 

 

Similar post

Addition of two numbers in Java

Addition of two numbers in C

Addition of two numbers in C++

Addition of two numbers in Python

Addition of two numbers in C#

Addition of two numbers in PHP

Addition of two numbers in JavaScript

 

Sum of two numbers in Java using method

Sum of two numbers in C++ using function

Sum of two numbers in Python using function

 

C program to add two numbers without using arithmetic operators

C++ program to add two numbers without using arithmetic operators

Python program to add two numbers without using arithmetic operators

 

Suggested for you

For loop in Java language

While loop in Java language

The method in Java language

Operator in Java language

variable in Java language

Data type of Java

 

Operator in C language

Function in C language

Data type in C language

 

Java program to multiply two numbers using method
Addition of two numbers in Java using method
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.

View Comments

  • As I write a program in c language as per prescribed I got errors like syntax ,prototype,statement is missing, unterminated string or character constant . I am a fresher you are requested to send me a fully solved program like sum of two integers. on my e mail. nksharma0709@gmail.com. NARESH KUMAR SHARMA

Recent Posts

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago

Java program to check odd or even using recursion

Java program to check odd or even using recursion In this tutorial, we discuss a…

2 months ago