I have seen a ton of java answers to this question but i hav

I have seen a ton of java answers to this question, but i havent seen it done doing C#. Help is needed

Write a program that uses for loops to perform the following steps:

a. Prompt the user to input two integers: firstNum and secondNum (firstNum must be less than secondNum).

b. Output all odd numbers between firstNum and secondNum.

c. Output the sum of all even numbers between firstNum and secondNum.

d. Output the numbers and their squares between 1 and 10.

e. Output the sum of the square of the odd numbers between firstNum and secondNum.

f. Output all uppercase letters.

Then Redo using while loops.

Then Redo using do...while loops.

Solution

using System;
using System.Collections.Generic;
namespace Program
{
class Program
{
static void Main(string[] args)
{
int firstNum,secondNum, sumeven = 0,sumodd=0;
Console.WriteLine(\"Enter a first Number : \");
firstNum = int.Parse(Console.ReadLine());
           Console.WriteLine(\"Enter a second Number : \");
secondNum = int.Parse(Console.ReadLine());
           if(firstNum>secondNum)
           Console.WriteLine(\"Number 1 should be less than number 2\");
           else{
           Console.WriteLine(\"Odd numbers between \"+firstNum+\" and \"+secondNum+\" are:\");
for(int i=firstNum;i<=secondNum;i++)
{
if(i% 2 != 0){
           Console.WriteLine(i);
           sumodd= (i*i)+sumodd;}
           else{
           sumeven=sumeven+i;
           }
}
Console.WriteLine(\"Sum of all even numbers between \"+firstNum+\" and \"+secondNum+\" is \"+ sumeven);
           Console.WriteLine(\"sum of the square of the odd numbers between \"+firstNum+\" and \"+secondNum +\" is \"+ sumodd);
   for(int j=1;j<=10;j++){
   Console.WriteLine(\"The number is \" + j +\" and the square value is \" + j*j);
   }
}

string Str = \"ABCDEFGHIJKLMOPQRSTUVWXYZ\";
Console.WriteLine(\"The Uppercase letters are \"+ Str);
   }
      
}
}

-----------------------------------------------------------------------------------using while loop--------------------------------------------------

using System;
using System.Collections.Generic;
namespace Program
{
class Program
{
static void Main(string[] args)
{
int firstNum,secondNum, sumeven = 0,sumodd=0;
Console.WriteLine(\"Enter a first Number : \");
firstNum = int.Parse(Console.ReadLine());
           Console.WriteLine(\"Enter a second Number : \");
secondNum = int.Parse(Console.ReadLine());
           if(firstNum>secondNum)
           Console.WriteLine(\"Number 1 should be less than number 2\");
           else{
           Console.WriteLine(\"Odd numbers between \"+firstNum+\" and \"+secondNum+\" are:\");
           int i=firstNum;
           while(i<=secondNum)
//for(int i=firstNum;i<=secondNum;i++)
{
if(i% 2 != 0){
           Console.WriteLine(i);
           sumodd= (i*i)+sumodd;}
           else{
           sumeven=sumeven+i;
           }
           i++
}
Console.WriteLine(\"Sum of all even numbers between \"+firstNum+\" and \"+secondNum+\" is \"+ sumeven);
           Console.WriteLine(\"sum of the square of the odd numbers between \"+firstNum+\" and \"+secondNum +\" is \"+ sumodd);
   //for(int j=1;j<=10;j++)
   int j =1;
   while(j<=10)
   {
   Console.WriteLine(\"The number is \" + j +\" and the square value is \" + j*j);
   j++;
   }
}

       string Str = \"ABCDEFGHIJKLMOPQRSTUVWXYZ\";
       Console.WriteLine(\"The Uppercase letters are \"+ Str);
   }
      
}
}

---------------------------do while loop----------------------------------------

do while loop is similar to while loop but thw syntax is

in case of while

code:

int i=firstNum;
           do
//for(int i=firstNum;i<=secondNum;i++)
{
if(i% 2 != 0){
           Console.WriteLine(i);
           sumodd= (i*i)+sumodd;}
           else{
           sumeven=sumeven+i;
           }
           i++
}while(i<=secondNum)

int j =1;
   do
   {
   Console.WriteLine(\"The number is \" + j +\" and the square value is \" + j*j);
   j++;
   }while(j<=10)

I have seen a ton of java answers to this question, but i havent seen it done doing C#. Help is needed Write a program that uses for loops to perform the follow
I have seen a ton of java answers to this question, but i havent seen it done doing C#. Help is needed Write a program that uses for loops to perform the follow
I have seen a ton of java answers to this question, but i havent seen it done doing C#. Help is needed Write a program that uses for loops to perform the follow

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site