Sum of Digits in C Using For Loop

Sum of the digits in c. 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;



Enter the number


Total = 1035

For Loop in C Program

A for loop is a repetition control structure that allows us to create a loop that runs a set number of times. The loop allows us to do an arbitrary number of steps in a single line. A loop variable is used to regulate the loop in for loop. Using this program we can execute the sum of the digits in c.

AND operator in C Program and Segmentation Fault

On two Boolean expressions, this operator conducts logical conjunction. The AND operator yields True if both expressions evaluate to True. The AND operator gives False if either or both phrases evaluate to False.

A Core Dump/Segmentation Fault is a type of error that occurs when you access memory that “doesn’t belong to you.” A core dump occurs when a piece of code tries to perform read and write operations in a read-only memory location or a released memory block.

Return Statement in C

A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the caller function a value.