.1. Print the first 7 odd numbers in descending order using for loop
2. Print the product of first 5 natural numbers using for loop
3. Print your name 10 times in different lines using while loop
4. Print the square of first 10 even numbers in descending order using while loop
5. Print the cube of first 8 multiples of 6 in descending order using do-while loop.
6. Print the twice of first 12 natural number in ascending order using do-while
loop.
PART II [3x5=15 marks]
Answers
// C++ implementation of the approach
#include <bits/stdc++.h>
using namespace std;
// Function that returns true if n is prime
bool isPrime(int n)
{
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
// Function that return true if the product
// of the first n natural numbers is divisible
// by the sum of first n natural numbers
bool isDivisible(int n)
{
if (isPrime(n + 1))
return false;
return true;
}
// Driver code
int main()
{
int n = 6;
if (isDivisible(n))
cout << "Yes";
else
cout << "No";
return 0;
Answer:
imakakaisiwuwuwueueuueheheheheh