0% found this document useful (0 votes)
2 views

CSharp_Program (1)

The document contains four C# programs demonstrating basic programming concepts. Program 1 calculates the sum of three user-input numbers, Program 2 checks if a number is even or odd, Program 3 counts from 1 to 10 using a for loop, and Program 4 prints the days of the week. Each program includes user interaction and outputs results to the console.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CSharp_Program (1)

The document contains four C# programs demonstrating basic programming concepts. Program 1 calculates the sum of three user-input numbers, Program 2 checks if a number is even or odd, Program 3 counts from 1 to 10 using a for loop, and Program 4 prints the days of the week. Each program includes user interaction and outputs results to the console.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

C# Programs

using System;

class Program1
{
static void Main()
{
// Program 1: Find the Sum of Three Greatest Numbers
Console.Write("Enter first number: ");
int num1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number: ");
int num2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter third number: ");
int num3 = Convert.ToInt32(Console.ReadLine());
int greatestSum = num1 + num2 + num3;
Console.WriteLine("Sum of the three numbers: " + greatestSum + "\n");
}
}

using System;

class Program2
{
static void Main()
{
// Program 2: Check if a Number is Even or Odd
Console.Write("Enter a number to check even or odd: ");
int number = Convert.ToInt32(Console.ReadLine());
if (number % 2 == 0)
{
Console.WriteLine("The number " + number + " is Even.\n");
}
else
{
Console.WriteLine("The number " + number + " is Odd.\n");
}
}
}

using System;

class Program3
{
static void Main()
{
// Program 3: Simple For Loop Example
Console.WriteLine("Counting from 1 to 10:");
for (int i = 1; i <= 10; i++)
{
Console.WriteLine(i);
}
Console.WriteLine();
}
}

using System;

class Program4
{
static void Main()
{
// Program 4: Print the Days of the Week
string[] days = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
Console.WriteLine("Days of the Week:");
foreach (string day in days)
{
Console.WriteLine(day);
}
}
}

You might also like