In: Computer Science
Please code C#
8. Write a program that prompts the user to enter an integer. The program then determines and displays the following:
I have uploaded the Images of the code, Typed code and Output of the Code. I have provided explanation using comments(read them for better understanding).
Images of the Code:
Note: If the below code is missing indentation
please refer code Images
Typed Code:
using System;
class HelloWorld {
static void Main() {
Console.WriteLine("Enter a number:");
int a;
//getting input from the user
//converting it to integer and storing it to "a"
a = Convert.ToInt32(Console.ReadLine());
//if number is divisible by both 5 and 6
if(a % 5 == 0 && a % 6 == 0)
{
//printing that the number is divisible by both 5 and 6
Console.WriteLine("{0} is divisible by 5 and 6",a);
}
//if number is only divisible by 5
else if(a % 5 == 0)
{
//printing that the number is only divisible by 5
Console.WriteLine("{0} is only divisible by 5",a);
}
//if number is only divisible by 6
else if(a % 6 == 0)
{
//printing that the number is only divisible by 6
Console.WriteLine("{0} is only divisible by 6",a);
}
//if number is not divisible by both 5 and 6
else
{
//printing that the number is not divisible by both 5 and 6
Console.WriteLine("{0} is not divisible by 5 and 6",a);
}
}
}
//code ended here
Output 1:
Output 2:
Output 3:
Output 4:
If You Have Any Doubts. Please Ask Using Comments.
Have A Great Day!