C program to print sum of digits using for loop

C program to print sum of digits using for loop. This program will print the sum of numbers in c programs. To add number which is entered by the users like if you enter the number 3 it will print number 6.

#include <stdio.h>
int main() 
{
int n, i, total = 0;
printf("Enter the number ");
scanf("%d", &n);
for (i = 1; i <= n; ++i) 
{
total += i;
}
printf("total = %d", total);
return 0;
}

Output

Enter the number

45

Total = 1035