Simple C program for print the sum of all odd numbers from 1 to n
Sum of the Digits
In mathematics, the digit sum of a given integer is the sum of all its digits (e.g. the digit sum of 84001 is calculated as 8+4+0+0+1 = 13)
Odd Number
An odd number is an integer which is not a multiple of two. If it is divided by two the result is a fraction. One is the first odd positive number. The next four bigger odd numbers are three, five, seven, and nine. So some sequential odd numbers are: {1,3,5,7,9,11,13,15,17,19,21,23,25. And then you add all the number up if its over 1,000 its odd if under 1,000 its even..}
Simple C program for print the sum of all odd numbers from 1 to n:
/** Simple C program for print the sum of all odd numbers from 1 to n
* Simple calculation programs
*/
#include <stdio.h>
int main()
{
int i, limit, sum=0;
/* Read Limit Nuber for find sum of odd numbers */
printf("Enter Limit : ");
scanf("%d", &limit);
/* Find the sum of all odd number */
for(i=1; i<=limit; i+=2)
{
sum += i;
printf("\nOdd Number Is : %d , Sum : %d",i,sum);
}
printf("\nTotal Sum of Odd numbers 1 to %d = %d", limit,sum);
return 0;
}
Sample Output
Enter Limit : 13
Odd Number Is : 1 , Sum : 1
Odd Number Is : 3 , Sum : 4
Odd Number Is : 5 , Sum : 9
Odd Number Is : 7 , Sum : 16
Odd Number Is : 9 , Sum : 25
Odd Number Is : 11 , Sum : 36
Odd Number Is : 13 , Sum : 49
Total Sum of Odd numbers 1 to 13 = 49
C Calculation Programs
- Area Of Circle Example C Program
- Area Of Square Example C Program
- Area Of Rectangle Example C Program
- Odd Or Even Example C Program
- Sum of Digits Example C Program
- Circumference Of Circle C Example Program
- Simple C program for print the sum of all odd numbers from 1 to n
- Simple Program for Convert Feet to Inches In C Programming
- Odd Or Even Example C Program Using function
Read More Articles
- Use of getch(),getche() and getchar() in C
- Switch Case Statement Example Program In C Programming Language
- C Character Set
- Convert a Floating-point value to an Integer in C
- Data Input and Output gets and puts Example Program In C
- Special Operators In C
- Pointer Representation and Pointer Example Programs
- C Data Input and Data Output
- Simple While Loop Example Program In C Programming Language
- Data Output printf and putchar Example Program In C
- C Introduction
- C Operators
- Storage Classes In C
- C Pointers
- File Management
- C Identifiers
- Loop Control Statements
- Hello World - Simple C Program
- C Array
- Single Character Output Function : putchar()
- C Reserve Words
- C Specific Properties and Implementation
- If else Statement Example Program In C Programming Language
- If Statement Example Program In C Programming Language
- Confusing Array in C ( Array Representation and Initialization )