You are on page 1of 7

PRACTICE TASKS FOR (FOR LOOP)

• Name: Shaikh Nehal Ahmed


• Roll No.:028
Task 1: Write a program that prints the first 50 even numbers by using for loop

STATEMENTS:
int main()
{
int x; OUTPUT

for (x = 0; x <= 50; x += 2)


cout << x << endl;

}
Task 2: Write a C++ program which will print even numbers from 20 to 1 by using for loop.

STATEMENTS:
using namespace std; • OUTPUT:
int main()
{
int x;

for (x = 20; x >= 1; x -= 2)


cout << x << endl;
}
Task 4: Write a C++ program which will print first 10 numbers which are multiple of 7.

STATEMENT:
Using namespace std;
{ • OUTPUT:
int x, result;

for (x = 1; x <= 10; x++)


{
result = 7 * x;
cout << "7 x " << x << " = " << result << endl;
}
}
Task 5: Write a C++ program that prints the sum of first 10 natural numbers.

STATEMENT:
using namespace std;
int main() • OUTPUT:
{
int x,add;
add = 0;

cout << "First 10 natural numbers\n";


for (x = 1; x <= 10; x++)
{
cout << x << endl;

add=add+x;
}
cout << "Sum of first 10 natural numbers: " << add<<endl;
}
Task 6: Write a C++ program that prints the series 1 2 4 8 16 32 64 128.

STATEMENT:
using namespace std; • OUTPUT:
int main()
{
int x;

for (x =1; x <=128; x *=2)


cout << x << endl;

}
Task 7: Write a C++ program that prints the series 3 6 9 12 15 18 21 24…..60.

STATEMENT:

using namespace std; • OUTPUT:


int main()
{
int x;

for (x = 3; x <= 60; x += 3)


cout << x << endl;
}

You might also like