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:
/*## print the sum of all odd numbers from 1 to n In C++*/
/*## Calculation C++ Programs, Datatype C++ Programs, Basic C++ Programs*/
#include <iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
int main() {
// Declare Variables
int i, limit, sum = 0;
cout << "Simple C++ Program : print the sum of all odd numbers from 1 to n\n";
cout << "\nEnter Limit : ";
cin>>limit;
for (i = 1; i <= limit; i += 2) {
sum += i;
cout << "\nOdd Number Is : " << i << " Sum : " << sum;
}
cout << "\n\nTotal Sum of Odd numbers 1 to " << limit << " : " << sum;
getch();
return (0);
}
Sample Output
Simple C++ Program : print the sum of all odd numbers from 1 to n
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++ Common Example Programs
- Factorial Using Loop Example Program In C++
- Factorial Using Function Example Program In C++
- Factorial Using Recursion Example Program In C++
- Find Prime Number ( Method1 ) Example Program In C++
- Find Prime Number ( Method2 ) Example Program In C++
- Fibonacci series Example Program In C++
- Example Program For Multiplication Value Using For Loop In C++
- 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
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Example Program For Copy Constructor In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Simple Example Program For Constructor In C++
- Factorial Using Function Example Program In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program for Inline Function Using C++ Programming
- Simple Program for Read user Input Using cin
- Simple Example Program For Constructor Overloading In C++
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Do While Loop Example Program In C++
- Simple Program for Binary Operator Overloading Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Simple Copy Constructor Example Program For Find Factorial In C++