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

PROGRAM 1.cs

The document contains three C# programs: the first simulates simple arithmetic operations (addition, subtraction, multiplication, division, and modulus) based on user input; the second identifies and prints Armstrong numbers between 1 and 1000; and the third lists all substrings of a given string using the Substring() method. Each program includes code snippets and sample outputs demonstrating their functionality. The programs are designed for educational purposes to illustrate basic programming concepts in C#.

Uploaded by

Ginny Weasly
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

PROGRAM 1.cs

The document contains three C# programs: the first simulates simple arithmetic operations (addition, subtraction, multiplication, division, and modulus) based on user input; the second identifies and prints Armstrong numbers between 1 and 1000; and the third lists all substrings of a given string using the Substring() method. Each program includes code snippets and sample outputs demonstrating their functionality. The programs are designed for educational purposes to illustrate basic programming concepts in C#.

Uploaded by

Ginny Weasly
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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

You might also like