C++ Programming Code Examples C++ > For Loops and While Loops Code Examples print the sum of all odd numbers from 1 to n: 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..} #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); }