# C program to calculate and print sum of two number

## Problem In Hand

### Sum of two numbers program in C is discussed below in various methods

Without using function
Using functions with out passing arguments
Using function by passing arguments

### Process and Solution Of Problem

Take input for two numbers and store them in two variables
calculate and store sum of the number in a third variable
further display the result

### Solution : Without using function Program/Source Code

```#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter 1st no ");
scanf("%d",&a);
printf("Enter 2nd no ");
scanf("%d",&b);
c=a+b;
printf("Sum = %d",c);
return 0;
}```

### Program Explanation

On execution of the program

* user enteres the first number and it is stored in a variable “a”
* user enteres the second number and it is stored in a variable “b”
* further calculation is performed and sum of values stored in “a” and “b” are stored in a variable “c” i.e. c=a+b;
* then the result is displayed on the screen

### Output:

```Enter 1st no 10
Enter 2nd no 20
Sum = 30```

### Solution : Using function Without Passing Arguments Program/Source Code

```#include <stdio.h>
void sum()
{
int a,b,c;
printf("Enter 1st no ");
scanf("%d",&a);
printf("Enter 2nd no ");
scanf("%d",&b);
c=a+b;
printf("Sum = %d\n",c);
}

int main()
{
sum();
return 0;
}
```

Output:

Enter 1st no 10
Enter 2nd no 20
Sum = 30

### Solution : Using function Passing Arguments Program/Source Code

```#include <stdio.h>
void sum(int a,int b)
{
int c;
c=a+b;
printf("Sum = %d\n",c);
}

int main()
{
int a,b;
printf("Enter 1st no ");
scanf("%d",&a);
printf("Enter 2nd no ");
scanf("%d",&b);
sum(a,b);
return 0;
}
```

Output:

Enter 1st no 100
Enter 2nd no 200
Sum = 300

### Interview Questions

C Programming
C++ Programming
Class 11 (Python)
Class 12 (Python)
C Language
C++ Programming
Python

C Interview Questions
C++ Interview Questions