Please code C#
using System;
public class main
{
public static int Greater(int num1, int num2)
{
if(num1>num2)
return num1;
else if(num1<num2)
return num2;
else
return -1;
}
public static void Main()
{
for(int i=0;i<3;i++)
{
Console.Write("Enter a number: ");
int n1= Convert.ToInt32(Console.ReadLine());
Console.Write("Enter another number: ");
int n2= Convert.ToInt32(Console.ReadLine());
if(Greater(n1,n2)!=-1)
Console.WriteLine("The Greater of two numbers is : {0} \n", Greater(n1,n2) );
else
Console.WriteLine("The two number are same : {0}",Greater(n1,n2));
}
}
}
Here is the program that will asks the user to enter two number for three times by using a for loop and every time will print whether num1 is greater or num2 is greater.If both are same then it prints -1 as output.
SCREENSHOT OF THE OUTPUT :
Get Answers For Free
Most questions answered within 1 hours.