Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lab 5.1 (write C# program usingfor statements to accomplish the followin;g Tasks

ID: 3674853 • Letter: L

Question

Lab 5.1 (write C# program usingfor statements to accomplish the followin;g Tasks Write a for statement that will display the numbers from 1 to 20 Write a for statement that will display the numbers from 18 to 45 Write a for statement that will display the numbers from 10 to-10, in that order. Write a for statement that will display the multiples of 5 (5, 10,15. from 5 to 50 Write a for statement that will display all the numbers from 30 to 100 that are divisible by 7, Test your results. Lab 5.2 Find the value of sum in the following for statements Tasks a. int sum 100 for (int = 2; i 6; i.. 5) sum ; d. int sum = 100; for (int # 20, i > 16; i") sumi int sum = 50; for (int = 2: i

Explanation / Answer

1.
for(i=1;i<=20;i++)
   Console.WriteLine(i);

2.
for(i=18;i<=45;i++)
   Console.WriteLine(i);
3.
for(i=10;i>=-10;i--)
   Console.WriteLine(i);

4.
for(i=5;i<=50;i=i+5)
   Console.WriteLine(i);

5.
for(i=30;i<=100;i++)
{
   if((i%7)==0)
       Console.WriteLine(i);
}

a. 86
b. 28
c. error
d. error
e. error

5.3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
for(int i=2;i<=30;i=i+2)
sum+=i;

Console.WriteLine(sum);


}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
class Program
{
static void Main(string[] args)
{
int sum = 0,i=2;
while (i <= 30)
{
sum += i;
i = i + 2;
}
Console.WriteLine(sum);


}
}
}


5.4

switch(x)
{
   case 3:
       y=x-4;
       break;

   case 7:
       y=x*7;
       break;

   case 9:
       y=x+9;
       break;
   case 12:
       y=20+y/x;
       break;
   default:
       x=50;
       break;

}

5.5
if(amt>1000)
   Console.WriteLine("Benefactors="+amt);
else if(amt>=500 && amt<1000)
    Console.WriteLine("Patrons="+amt);
else if(amt>=100 && amt<500)
    Console.WriteLin("Supportors="+amt);
else if(amt>=1 && amt<100)
    Console.WriteLine("Contributors="+amt);

5.6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{
class Program
{
static void Main(string[] args)
{
int f=1,i;
Console.WriteLine("Enter number");
int n = Convert.ToInt32(Console.ReadLine());

while (i <= n)
{
f*= i;
i = i + 1;
}
Console.WriteLine("Factorial is "+f);


}
}
}