Addition using functions examples in C


This program is a C program that performs the addition of two numbers using a function.

  • The header file "stdio.h" is included, which contains the standard input/output library functions.
  • The "void add()" function is declared, which will perform the addition of two numbers.
  • The "main()" function is defined as the starting point of the program.
  • The "add()" function is called in the "main()" function using the "add()" function call statement.
  • The "add()" function definition follows the function declaration.
  • Three integer variables "a", "b", and "c" are declared.
  • The "printf()" function is used to print the prompt "Enter the two values:".
  • The "scanf()" function is used to get the two values from the user.
  • The sum of the two values is stored in the "c" variable using the addition operator.
  • The "printf()" function is used to print the result "Addition:%d" along with the value stored in the "c" variable.
  • The "return 0;" statement in the "main()" function is used to indicate that the program executed successfully.

Source Code Example : 1

#include<stdio.h>
void add();                                               //Function Declaration
int main()
{
  add();                                                  //Function Calling
  return 0;
}
void add()                                                //Function Definition
{
   int a,b,c;
   printf("\nEnter The Two values:");
   scanf("%d%d",&a,&b);
   c=a+b;
   printf("Addition:%d",c);
}
To download raw file Click Here

Output

Enter The Two values:3
4
Addition:7


This program is about print the an example for no return value and with argument using functions.

Source Code Example : 2

#include<stdio.h>
void add(int,int);
int main()
{
   int a,b;
   printf("\nEnter The Two Values:");
   scanf("%d%d",&a,&b);
   add(a,b);
   return 0;
}
void add(int a,int b)
{
   int c;
   c=a+b;
   printf("\nAddition:%d",c);
}
To download raw file Click Here

Output

Enter The Two values:3
4
Addition:7


This program is about example for return type without arguments using functions.

Source Code Example : 3

#include<stdio.h>
int add();
int main()
{
   printf("\nAddition:%d",add());
   return 0;
}
int add()
{
   int a,b,c;
   printf("\nEnter The Two Values:");
   scanf("%d%d",&a,&b);
   c=a+b;
   return c;
}
To download raw file Click Here

Output

Enter The Two values:3
4
Addition:7


This program is about example for return type with arguments using functions.

Source Code Example : 4

#include<stdio.h>
int add(int,int);
int main()
{
   int a,b;
   printf("\nEnter The Two Values:");
   scanf("%d%d",&a,&b);
   printf("\nAddition:%d",add(a,b));
   return 0;
}
int add(int a,int b)
{
   int c;
   c=a+b;
   return c;
}            
To download raw file Click Here

Output

Enter The Two values:3
4
Addition:7


List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C