107 308
Assignments Done
98.9%
Successfully Done
In March 2023

# Answer to Question #271805 in C# for chi

Question #271805

apply the following looping statement : for loop, while loop, and do while loop

Write a program that calculates and produces these two columns sequence numbers using the three looping statements:

Sequence nos. Squared

1 1

2 4

3 9

4 16

5 25

1
Expert's answer
2021-11-26T07:09:21-0500
using System;

namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
const int n = 5;
int i;

Console.WriteLine("1st Solution – using for loop");
for (i = 1; i <= n; i++)
{
int square = i * i;
Console.WriteLine("{0} {1}", i, square);
}

Console.WriteLine("2nd Solution – using while loop");
i = 0;
while (++i <= n)
{
int square = i * i;
Console.WriteLine("{0} {1}", i, square);
}

Console.WriteLine("3rd Solution - using do while loop");
i = 1;
do
{
int square = i * i;
Console.WriteLine("{0} {1}", i, square);
}
while (++i <= n);
return;
}
}
}



Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

#### Comments

No comments. Be the first!

### Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS