Answer:
// here is code in C.
#include <stdio.h>
// main function
int main(void) {
// variable
long long int n;
printf("Enter the value of N:");
// read the value of n
scanf("%llu",&n);
// calculate the sum from 1 to N
long long int sum=n*(n+1)/2;
// print the sum
printf("\\sum of all number from 1 to %llu is: %llu",n,sum);
return 0;
}
Step-by-step explanation:
Read the value of n from user.Then find the sum of all number from 1 to N with the formula sum of first N natural number.That is (n*(n+1)/2). This will give the sum from 1 to N.
Output:
Enter the value of N:100
sum of all number from 1 to 100 is: 5050
Enter the value of N:1000000
sum of all number from 1 to 1000000 is: 500000500000