PROGRAM 1
1. Develop C# program to simulate simple arithmetic calculation for Addition,
Subtraction, Multiplication ,Division and Mod operation.Read the operator and
operands through console.
using System;
// This is the beginning of the Exercise7 class
public class Exercise7
{
// This is the main method where the program execution starts
public static void Main()
{
// Prompting the user to enter the first number
Console.Write("Enter a number: ");
// Reading the first number entered by the user and converting it to an
integer
int num1 = Convert.ToInt32(Console.ReadLine());
// Prompting the user to enter the second number
Console.Write("Enter another number: ");
// Reading the second number entered by the user and converting it to an
integer
int num2 = Convert.ToInt32(Console.ReadLine());
// Displaying addition of the two numbers
Console.WriteLine("{0} + {1} = {2}", num1, num2, num1 + num2);
// Displaying subtraction of the two numbers
Console.WriteLine("{0} - {1} = {2}", num1, num2, num1 - num2);
// Displaying multiplication of the two numbers
Console.WriteLine("{0} x {1} = {2}", num1, num2, num1 * num2);
// Displaying division of the two numbers
Console.WriteLine("{0} / {1} = {2}", num1, num2, num1 / num2);
// Displaying modulus (remainder) of the two numbers
Console.WriteLine("{0} mod {1} = {2}", num1, num2, num1 % num2);
}
}
OUTPUT
Sample Output:
Enter a number: 10
Enter another number: 2
10 + 2 = 12
10 - 2 = 8
10 x 2 = 20
10 / 2 = 5
10 mod 2 = 0
PROGRAM 2
2.Develop a c# program to print Armstrong Number between 1 to 1000.
using System;
class Program
{
static void Main()
{
int a, b, c, d;
for (int i = 1; i <= 1000; i++)
{
a = i / 100;
b = (i - a * 100) / 10;
c = (i - a * 100 - b * 10);
d = a * a * a + b * b * b + c * c * c;
if (i == d)
{
System.Console.WriteLine("{0}", i);
}
}
Console.Read();
}
}
OUTPUT
1
153
370
371
407
1000
PROGRAM 3
3. Develop a c# program to list all Sub strings in a given string.[ us of Sub-
string() Method]
using System;
namespace Substring
{
class Substring
{
static void Main(string[] args)
{
Console.Write("Enter a String : ");
string inputString = Console.ReadLine();
int len = inputString.Length;
Console.WriteLine("All substrings for given string are : ");
//This loop maintains the starting character
for (int i = 0; i < len; i++)
{
//This loop adds the next character every iteration for the substring and then
print
for (int j = 0; j < len - i; j++)
{
Console.Write (inputString.Substring(i, j + 1) + " ");
}
}
Console.ReadKey();
}
}
}
OUTPUT
secabiet@secabiet-Vostro-3470:~/Desktop/program3$ mcs -
out:Substring.exe Substring.cs
secabiet@secabiet-Vostro-3470:~/Desktop/program3$ mono Substring.exe
Enter a String : secab
All substrings for given string are :
s se sec seca secab e ec eca ecab c ca cab a ab b