In: Computer Science
Write a C program which adds up all the numbers between 1 and 50. Use any type of loop
I am providing the code for sum of digits from 1 to 50 including both. In case you need the code for sum of digit from 1 to 50 excluding 1 and 50 ( 2 to 49 ), then change the for loop condition (line number 7) from 'for (int i = 1; i <= 50; i++)' to 'for (int i = 2; i < 50; i++)'.
Steps:
Code Screenshot:

Output:

Code To Copy:
#include <stdio.h>
int main()
{
// declare and initialize sum variable as 0
int sum = 0;
// start a for loop with iterator variable ranging from 1 to 50
for (int i = 1; i <= 50; i++)
{
// each iteration increment sum with i
sum = sum + i;
}
// print sum
printf("Sum of numbers between 1 and 50: %d", sum);
return 0;
}