adding all the numbers from 1 to n c code example
Example 1: add 2 numbers in c
#include<stdio.h>
int main() {
int a, b, sum;
printf("\nEnter two no: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum : %d", sum);
return(0);
Example 2: sum of n natural numbers in c
int addNumbers(int n)
{
int count, sum = 0;
for(count=1; count <= n; count++)
{
sum = sum + count;
}
return sum;
}