Categories




C program to add two number using function

So today we will learn “C program to add two number using string function” . First let me define “function” . If you want to learn about function then CLICK HERE .

If you are beginner in programming then visit following topics . Which help you to understand below program.

Switch Cases
Array and Types
– Function 
String  

A function is a group of statement that together performs a specific task. So this is just a simple definition of the function .

Advantage of Function:

–  Code Re-usability.
–  Develop an application in module format.
–  Easy to debug the program.
–  Code optimization.
–  Code is easy to read.

So without delay let’s go programming.

C Program To Add Two Number Using String Function
 #include<stdio.h>  
#include<conio.h> 
void sum(); //declaring a function
main()
{
 int a,b;
 printf("n Enter a number:");
 scanf("%d",&a);
 printf("n Enter a number:");
 scanf("%d",&b);
 sum();  //calling function getch(); 
}
void sum()  // defining functionint 
{
 int a,b,c=0;
 c=a+b;
 printf("n Sum:%d",c);
}


OUTPUT:

 

Output:

Enter number:10
Enter number:20
Sum=30


EXPLANATION:
In the above program, we have just solved the simple problem to “C program to add two number using the function”. If you are getinnen then you may have one question i.e  What is going?

So I’m here to make you understand every program. In the program, we have solved to add number using the function . So we need to define return type function in the header . Then, as usual, taking an integer and ask the user to enter numbers. In this function we have use calling function i,e “sum()” . So which is used to print values when we return value from defining the function . Now we define defining a function and perform all mathematical operation and return value to calling function and print value as output .

Concept of function,function definition, function prototype

If you have any problem then you can comment below or visit my social media page contact me. I will be so pleased to help you and available 24 hours in your help  .

SIMILAR POST:

C program to read 2D array of size 2*3 from user and display it.
Function Concept function, function definition, function prototype.
C program to arrange given number in descending order using function.

You can solve this problem in this way too. Which give same result .

 C Program To Add Integer Using Function 

 

 
 #include<stdio.h>  
#include<conio.h> 
int sum(int);
 main()
{
 int n,c;
 printf("n Enter number:");
 scanf("%d",&n);
 c=sum(n);
 printf("sum=%d",c);
 getch();
}
int sum(int n)
{
 int sum=0;
 for(int i=1;i<n;i++)
 {
  sum=sum+i;
 }
 return(sum);
}

Other Problems: (do not forget to visit)

Program to find factorial of given number using loop for loop.
Write a menu driven program in C to find area and perimeter of rectangle .
C program to find samallest number among given three number

Loading...

admin

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!