- 1. Adding two numbers with output of previous with new input .
- #include <stdio.h>
- int main() {
- int i,n,sum=0;
- printf("Enter the value of n: ");
- scanf("%d",&n);
- for(i=1; i<=n; i++)
- {
- printf("%d +%d =",sum,i);
- sum=sum+i;
- printf("%d\n",sum);
- }
- return 0;
- }
- OUTPUT :
- Enter the value of n:10
- 0 +1 =1
- 1 +2 =3
- 3 +3 =6
- 6 +4 =10
- 10 +5 =15
- 15 +6 =21
- 21 +7 =28
- 28 +8 =36
- 36 +9 =45
- 45 +10 =55
- 2. Performing sum of two numbers using,
- Function with arguments and with return type.
- #include<stdio.h>
- int sum(int,int);
- int main()
- { int a,b,res;
- a=10;
- b=34
- res=sum(a,b);
- printf("Sum= %d",res);
- return 0;
- }
- int sum(int x,int y)
- {
- int sum=0;
- sum=x+y;
- return sum;
- }
- OUTPUT :
- Sum= 44
- 3. Performing sum of two numbers using ,
- Function with arguments and without return type
- #include<stdio.h>
- void sum(int,int);
- int main()
- { int a,b;
- a=54;
- b=32;
- sum(a,b);
- return 0;
- }
- void sum(int x,int y)
- {
- int sum=0;
- sum=x+y;
- printf("Sum=%d",sum);
- }
- OUTPUT :
- Sum=86
- 4. Sum of natural number with using while loop .
- #include<stdio.h>
- int main()
- {
- int n,sum=0;
- while(1)
- {
- printf("\nEnter The Natural Number : ");
- scanf("%d",&n);
- sum=(n*(n+1))/2;
- printf("\nSum Of Natural Number Is = %d\n",sum);
- }
- return 0;
- }
- OUTPUT :
- Enter The Natural Number : 5
- Sum Of Natural Number Is = 15
- Enter The Natural Number :
Program to perform addition on numbers using C language
Please wait 0 seconds...
Scroll Down and click on Go to Link for destination
Congrats! Link is Generated