C# Questions Answers-C# loops (PartII)


C# loops (PartII)

1. Change the following C# code from using a while loop to for loop:
x=1;
while(x<10){
  Console.Write("{0}\t",x);
  ++x;
}
Check answer 2. Change the following C# code from a while loop to a for loop:
int x;
x=int32.parse(Console.ReadLine());
while(x!=10){
  Console.Write("{0}\t",x);
  x=int32.parse(Console.ReadLine());
}
Check answer 3. What would be the output from the following C# code segment?
x=10;
while(x>5){
  Console.WriteLine("{0}",x);
  x--;
}
Check answer 4. Change the following C# code from a for loop to a while loop:
for(i=1;i<50;i++)
  Console.Write("{0}\t",i);
Check answer 5. What would be printed from the following C# code segment?
for(i=20;i>0;i-=2)
  Console.WriteLine("{0}",i);
Check answer 6. What would be printed from the following C# code segment?
for(x=1;x<=5;x++){
     for(y=1;y<=x;y++)
         Console.Write("{0}\t",x);
  Console.WriteLine();
}
Check answer 7. Change the following C# code from a do while loop to a while loop:
x=0;
do{
  Console.Write("{0}\t",x);
  x++;
 }while(x<10);
Check answer


Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.