Notification texts go here Contact Us Click here

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

  1. 1Adding two numbers with output of previous with new input .
  2.  
  3.   #include <stdio.h>
  4.     int main() {
  5.     int i,n,sum=0;
  6.     printf("Enter the value of n: ");
  7.     scanf("%d",&n);
  8.     for(i=1; i<=n; i++)
  9.     {
  10.       printf("%d +%d =",sum,i);
  11.       sum=sum+i;
  12.       printf("%d\n",sum);
  13.     }
  14.     return 0;
  15.     }
  16.  
  17. OUTPUT :
  18.  
  19. Enter the value of n:10
  20. 0 +1 =1
  21. 1 +2 =3
  22. 3 +3 =6
  23. 6 +4 =10
  24. 10 +5 =15
  25. 15 +6 =21
  26. 21 +7 =28
  27. 28 +8 =36
  28. 36 +9 =45
  29. 45 +10 =55
  30.  
  31. 2Performing sum of two numbers using,
  32. Function with arguments and with return type.
  33.  
  34.  
  35. #include<stdio.h>
  36. int sum(int,int);
  37. int main()
  38. {   int a,b,res;
  39.     a=10;
  40.     b=34
  41.     res=sum(a,b);
  42.     printf("Sum= %d",res);
  43.     return 0;
  44. }
  45. int sum(int x,int y)
  46. {
  47.     int sum=0;
  48.     sum=x+y;
  49.     return sum;
  50. }
  51.  
  52. OUTPUT :
  53.         Sum= 44
  54.  
  55.  
  56. 3.  Performing sum of two numbers using ,
  57. Function with arguments and without return type
  58.  
  59.  
  60.  
  61. #include<stdio.h>
  62. void sum(int,int);
  63. int main()
  64. {   int a,b;
  65.     a=54;
  66.     b=32;
  67.     sum(a,b);
  68.     return 0;
  69. }
  70. void sum(int x,int y)
  71. {
  72.     int sum=0;
  73.     sum=x+y;
  74.     printf("Sum=%d",sum);
  75. }
  76.  
  77.  
  78. OUTPUT :
  79.         Sum=86
  80.  
  81.  
  82. 4Sum of natural number with using while loop .
  83.  
  84.  
  85.  
  86. #include<stdio.h>
  87.  
  88. int main()
  89.  
  90. {
  91.  
  92.     int n,sum=0;
  93.  
  94.     while(1)
  95.  
  96.     {
  97.  
  98.  printf("\nEnter The Natural Number : ");
  99.  
  100.     scanf("%d",&n);
  101.  
  102.  sum=(n*(n+1))/2;
  103.  
  104.  printf("\nSum Of Natural Number Is  = %d\n",sum);
  105.  
  106.  }
  107.  
  108.  return 0;
  109.  
  110. }
  111.  
  112. OUTPUT :
  113.  
  114.  
  115. Enter The Natural Number : 5
  116. Sum Of Natural Number Is  = 15
  117.  
  118. Enter The Natural Number : 

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.