Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
8 views3 pages

Basic Level For Loop

The document provides a series of basic programming exercises in C++ that cover fundamental concepts such as loops, conditionals, and arithmetic operations. Each exercise includes a code snippet and its corresponding output, ranging from printing numbers and calculating sums to displaying ASCII values and counting digits. These examples serve as practical exercises for beginners to enhance their programming skills.

Uploaded by

Akash Satdeve
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Basic Level For Loop

The document provides a series of basic programming exercises in C++ that cover fundamental concepts such as loops, conditionals, and arithmetic operations. Each exercise includes a code snippet and its corresponding output, ranging from printing numbers and calculating sums to displaying ASCII values and counting digits. These examples serve as practical exercises for beginners to enhance their programming skills.

Uploaded by

Akash Satdeve
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Basic Level (1–10)

1. Print numbers from 1 to 10

#include<iostream>
using namespace std;
int main() {
for(int i = 1; i <= 10; i++)
cout << i << " ";
return 0;
}

Output: 1 2 3 4 5 6 7 8 9 10

2. Print even numbers between 1 and 20

#include<iostream>
using namespace std;
int main() {
for(int i = 2; i <= 20; i += 2)
cout << i << " ";
return 0;
}

Output: 2 4 6 8 10 12 14 16 18 20

3. Print odd numbers from 1 to 20

#include<iostream>
using namespace std;
int main() {
for(int i = 1; i <= 20; i += 2)
cout << i << " ";
return 0;
}

Output: 1 3 5 7 9 11 13 15 17 19

4. Sum of numbers from 1 to 100

#include<iostream>
using namespace std;
int main() {
int sum = 0;
for(int i = 1; i <= 100; i++)
sum += i;
cout << "Sum = " << sum;
return 0;
}
Output: Sum = 5050

5. Print multiplication table of 5

#include<iostream>
using namespace std;
int main() {
for(int i = 1; i <= 10; i++)
cout << "5 * " << i << " = " << 5 * i << endl;
return 0;
}

Output:

5 * 1 = 5
5 * 2 = 10
...
5 * 10 = 50

6. Factorial of a number (e.g., 5)

#include<iostream>
using namespace std;
int main() {
int fact = 1;
for(int i = 1; i <= 5; i++)
fact *= i;
cout << "Factorial = " << fact;
return 0;
}

Output: Factorial = 120

7. Print reverse from 10 to 1

#include<iostream>
using namespace std;
int main() {
for(int i = 10; i >= 1; i--)
cout << i << " ";
return 0;
}

Output: 10 9 8 7 6 5 4 3 2 1

8. Display squares of numbers 1 to 10

#include<iostream>
using namespace std;
int main() {
for(int i = 1; i <= 10; i++)
cout << i*i << " ";
return 0;
}

Output: 1 4 9 16 25 36 49 64 81 100

9. Print ASCII values of A to Z

#include<iostream>
using namespace std;
int main() {
for(char ch = 'A'; ch <= 'Z'; ch++)
cout << ch << " = " << (int)ch << endl;
return 0;
}

Output (First 3 lines):

A = 65
B = 66
C = 67
...
Z = 90

10. Count digits in a number (e.g., 12345)

#include<iostream>
using namespace std;
int main() {
int num = 12345, count = 0;
for(; num != 0; num /= 10)
count++;
cout << "Digits = " << count;
return 0;
}

Output: Digits = 5

You might also like