loop c+++
loop c+++
int sum = 0;
sum += i; }
Using while
int sum = 0, i = 1;
sum += i;
i++; }
int sum = 0, i = 1;
do {
sum += i;
i++; }
int sum = 0;
sum += i; }
int sum = 0, i = 5;
sum += i;
i += 5; }
do {
sum += i;
i += 5;
sum += 1.0 / i; }
int i = 1;
sum += 1.0 / i;
i++; }
int i = 1;
do {
sum += 1.0 / i;
i++;
int i = 1;
product *= i;
i++; }
int i = 1;
do {
product *= i;
i++;
2 #include <iostream>
int main() {
return 0;
3 #include <iostream>
bool isPrime(int n) {
if (n <= 1)
return false;
if (n % i == 0)
return false; }
return true;
int main() {
cout << "Prime numbers between 1 and 100 are:" << endl;
if (isPrime(i))
return 0;
4 #include <iostream>
int main() {
int number;
int count = 0;
if (number < 0)
number = -number;
if (number == 0)
count = 1;
else {
while (number != 0) {
number /= 10;
count++; }
return 0;
5 #include <iostream>
}
int main() {
char choice;
do {
cout << "Error: Marks should be in the specified range (mid: 0–40, final: 0–60)." << endl;
} else {
cout << "Total: " << total << " | Grade: " << grade << endl;
cout << "Do you want to enter another record? (Y/N): ";
return 0;
6 #include <iostream>
int number;
if (number < 0) {
} else {
factorial *= i;
cout << "Factorial of " << number << " is: " << factorial << endl;
return 0;
7 #include <iostream>
int main() {
int n;
cin >> n;
if (n < 1) {
cout << "Please enter a number greater than 0." << endl;
return 1;
factorial *= i; // Compute i!
cout << "Sum of series 1! + 2! + ... + " << n << "! is: " << sum << endl;
return 0;
8 #include <iostream>
int main() {
for (int j = 65; j < 65 + i; j++) { // Inner loop: ASCII 'A' (65) to 65 + i - 1
return 0;
9 #include <iostream>
int main() {
return 0; }
10 #include <iostream>
int main() {
// A
// B
// C
cout << "\nC.\n";
// D
return 0;
11 #include <iostream>
int main() {
int day = 1;
total += temperature;
day++; }
cout << "\nAverage temperature over 10 days: " << average << " degrees\n";
return 0;
12 #include <iostream>
cout << "The result of the summation ∑ (2 * 3^i) from i = 1 to 30 is: " << sum << endl;
return 0;
13 #include <iostream>
int main() {
do {
cout << "Enter marks for student " << i << " (0 to 100): ";
cout << "Invalid mark. Please enter a value between 0 and 100.\n";
total += marks;
cout << "\nAverage marks of the five students: " << average << endl;
return 0; }
14 #include <iostream>
int main() {
char op;
switch (op) {
case '+':
cout << num1 << " + " << num2 << " equals " << (num1 + num2) << endl;
break;
case '-':
cout << num1 << " - " << num2 << " equals " << (num1 - num2) << endl;
break;
case '*':
cout << num1 << " * " << num2 << " equals " << (num1 * num2) << endl;
break;
case '/':
if (num2 == 0) {
cout << num1 << " / " << num2 << " can’t be computed: denominator is 0." << endl;
} else {
cout << num1 << " / " << num2 << " equals " << (num1 / num2) << endl;
break;
default:
return 0;
15 #include <iostream>
int main() {
char ch;
if (!isalpha(ch)) {
} else {
if (lowerCh == 'a' || lowerCh == 'e' || lowerCh == 'i' || lowerCh == 'o' || lowerCh == 'u') {
} else {
return 0; }
16 #include <iostream>
using namespace std;
int main() {
if (i % 2 == 0) {
return 0;
17 #include <iostream>
if (year % 4 != 0)
return false;
return false;
else
return true;
switch (month) {
return 30;
case 2:
default:
return 0; }
int main() {
} else {
cout << "Invalid day of month " << day << endl;
} else {
cout << day << "/" << month << "/" << year << " is a valid date" << endl;
return 0;