Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

1-Program To Addition, Subtraction, Multipication, Division: Output

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 28

1-PROGRAM TO ADDITION,SUBTRACTION,MULTIPICATION,DIVISION

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace add_mul_sum_div
{
class Program
{
static void Main(string[] args)
{
int a, b;
a = 10;
b = 4;
Console.WriteLine("Addition={0}", a + b);
Console.WriteLine("Subtraction={0}", a - b);
Console.WriteLine("Multiply={0}", a * b);
Console.WriteLine("Division={0}",(float)a / b);
}
}
}

Output :

2-PROGRAM TO INTERCHANGE VALUE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace interchange_Num
{
class Program
{
static void Main(string[] args)
{
int a, b;
a = 20;
b = 5;
Console.WriteLine("Before Interchange A = {0} And B = {1}", a, b);
a = a + b;
b = a - b;
a = a - b;
Console.WriteLine("After Interchange A = {0} And B = {1}", a, b);
Console.ReadLine();
}
}
}

Output :

3 -PROGRAM TO SUM OF FIRST TEN EVEN NATURAL NO. SQUARE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace eventensqure
{
class Program
{
static void Main(string[] args)
{
int sum = 0;
int even = 2;
for (int i = 1; i <= 10; i++)
{
sum = sum + even * even;
Console.WriteLine( "Sum Of even natural number's Square = {0}", sum);
even += 2;
}
Console.ReadLine();
}
}
}

Output :

4 PROGRAM TO PRIME NUMBER


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Primenumber2
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the value");
int limit =Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Prime numbers between 1 and " + limit);
for(int i=1; i < limit; i++)
{
Boolean isPrime = true;
for(int j=2; j < i ; j++)
{
if(i % j == 0)
{
isPrime = false;
break;
}
}
if(isPrime)
Console.Write(i + " ");
}
}
}
}

Output :

5 PROGRAM TO SERIES OF NUMBER


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace forbelow
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter The value");
int n = Convert.ToInt32(Console.ReadLine());
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("{0,3}", j);
}
Console.ReadLine();
}
}
}
}

Output :

6 PROGRAM TO FACTORIAL OF N
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dynamic_Factorial
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter the number: ");
int a = Convert.ToInt32(Console.ReadLine());
int result= fact(a);
Console.WriteLine("Factorial of the number is: " + result);
}
static int fact(int b)
{
if(b <= 1)
return 1;
else
return b * fact(b-1);
}
}
}

Output :

7 PROGRAM TO TRAINGALE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Triangle
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter the charecter\n");
string str1 = Console.ReadLine();
int i = 0;
char[] arr = new char[10];
foreach (char s in str1)
arr[i++] = s;
for (i = 0; i < str1.Length; i++)
{
for (int j = 0; j <= i; j++)
Console.Write(arr[j]);
Console.ReadLine();
}
}
}
}

Output :

8 PROGRAM TO MULTILEVEL INHERITANCE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Inheritance
{
class A
{
int i, j;
public void Nand()
{
Console.Write("This is Inheritance \n");
for (i = 0; i < 5; i++)
{
for (j = 5; j > i; j--)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
class B : A
{
public void Saxena()
{
for (int i = 5; i > 0; i--)
{
for (int j = 0; j < i; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
}
}
class C : B
{
public void Bramha()
{
int i, j;
for ( i = 1; i <= 5; i++)
{
for ( j = i; j >= 1; j--)
{
8

Console.Write(j);
}
Console.WriteLine();
}
}
}
class Program
{
static void Main(string[] args)
{
C obj = new C();
obj.Nand();
obj.Saxena();
obj.Bramha();
Console.Read();
}
}
}

Output :

9 PROGRAM TO INTERFACE
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace interface_me
{
interface A
{
void me();
}
interface B
{
void show();
}
class C : B, A
{
public void me()
{
Console.WriteLine("I LOVE MY India");
}
public void show()
{
Console.WriteLine("My Name is B.N.Saxena");
}
}
class Program
{
static void Main(string[] args)
{
C obj = new C();
obj.me();
obj.show();
Console.Read();
}
}}

Output :
10

10 PROGRAM TO DEFAULT & ARGUMENT CONSTRUCTOR


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Argument_Constructor
{
class Mul
{
int a, b;
public Mul()
{
a = 12;
b = 20;
}
public void display()
{
Console.WriteLine("Default Constructor");
Console.WriteLine(a);
Console.WriteLine(b);
}
public Mul(int x, int y)
{
int z = x * y;
Console.WriteLine("This is Argument Constructor");
Console.WriteLine(z);
}
}
class Program
{
static void Main(string[] args)
{
Mul obj = new Mul();
Mul ob = new Mul(4,5);
obj.display();
}
}}

Output :

11

11- PROGRAM TO COPY,DEFAULT & ARGUMENT CONSTRUCTOR


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Copy_Constructor
{
class BN
{
int a, b;
public BN()
{
a = 20;
b = 30;
}
public void display()
{
Console.WriteLine("Default Constructor");
Console.WriteLine(a + b);
}
public BN(int x, int y)
{
int z = x - y;
Console.WriteLine("Argument Constructor =" + z);
}
public BN(BN obj)
{
int d = obj.a;
int e = obj.b;
Console.WriteLine(d+"=Copy Constructor ="+e);
}
class Program
{
static void Main(string[] args)
{
BN obj = new BN();
obj.display();
BN obj1 = new BN(100, 60);
BN obj2 = new BN(obj);
} } } }

Output :
12

12 PROGRAM TO ABSTRACT
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace abstracclass
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Abstrt
{
abstract class GN
{
public abstract void nand();
public abstract void show();
}
class BN : GN
{
int i, j;
public override void nand()
{
Console.WriteLine("THis is Solution");
}
public override void show()
{
for (i = 5; i >= 0; i--)
{
for (j = 0; j <= i; j++)
{
Console.Write(i);
}
Console.WriteLine();
}
}
}
class ZN : BN
{
int x, y;
public override void nand()
{
x = 12;
y = 11;
}
13

public override void show()


{
Console.Write("This is value ");
Console.WriteLine("x=" + x);
Console.Write("This is value ");
Console.WriteLine("y=" + y);
}
}
class Program
{
static void Main(string[] args)
{
BN obj = new BN();
obj.nand();
obj.show();
ZN obj1 = new ZN();
obj1.nand();
obj1.show();
Console.Read();
}
}
}
}

Output :

14

13- PROGRAM TO DELEGATE


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
delegate int Area(int x,int y);
delegate int Area1(int x);
namespace delegate
{
class B
{
public static int Rectangle(int x, int y)
{
return (x * y);
}
public static int Triangle(int x, int y)
{
int s=((1/2)*(x * y));
return s;
}
public static int Circle(int x)
{
int z = (22 / 7) * (x * x);
return z;
}
}
class Program
{
static void Main(string[] args)
{
Area obj1 = new Area(B.Rectangle);
Area obj2 = new Area(B.Triangle);
Area1 obj3 = new Area1(B.Circle);
int a=obj1(4,5);
int b=obj2(2,3);
int c=obj3(7);
Console.WriteLine("Ractangle="+a);
Console.WriteLine("Triangle="+b);
Console.WriteLine("Circle="+c);
Console.Read();
}
}
}

15

Output :

16

14 - PROGRAM TO MULTICAST DELEGATES


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
delegate void Mdelegate();
namespace Multidelegate
{
class Bramha
{
public static void Nand()
{
Console.WriteLine("Lucknow");
}
public static void Show()
{
Console.WriteLine("Mumbai");
}
}
class Program
{
static void Main(string[] args)
{
Mdelegate m1 = new Mdelegate(Bramha.Nand);
Mdelegate m2 = new Mdelegate(Bramha.Show);
Mdelegate m3 = m1 + m2;
Mdelegate m4 = m1 - m2;
Console.Write("This is Multicast delegates \n");
m3();
m4();
Console.Read();
}
}
}

Output :

17

15 PROGRAM TO UNARY OPERATOR


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace U.operator
{
class Calu
{
public int number1, number2;
public Calu(int num1, int num2)
{
number1 = num1;
number2 = num2;
}
public static Calu operator-(Calu c1)
{
c1.number1 = -c1.number1;
c1.number2 = -c1.number2;
return c1;
}
public void show()
{
Console.WriteLine("Number1=" + number1);
Console.WriteLine("Number2=" + number2);
}
}
class Program
{
static void Main(string[] args)
{
Calu obj = new Calu(20, -30);
Console.Write("Unary Operator \n");
obj = -obj;
obj.show();
Console.Read();
}
}
}

Output :

18

16 - PROGRAM TO CALCULATOR
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Excel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Label l;
Label p;
Label q;
TextBox t;
TextBox r;
TextBox s;
private void Form1_Load(object sender, EventArgs e)
{
l = new Label();
l.Location = new Point(100, 70);
l.Text=("Value1");
Controls.Add(l);

p = new Label();
p.Location = new Point(100, 110);
p.Text = ("Value2");
Controls.Add(p);
q = new Label();
q.Location = new Point(100, 150);
q.Text = ("Result");
Controls.Add(q);
t = new TextBox();
t.Location = new Point(200, 70);
t.Text = (" ");
Controls.Add(t);
r = new TextBox();
19

r.Location = new Point(200, 110);


r.Text = (" ");
Controls.Add(r);
s = new TextBox();
s.Location = new Point(200, 150);
s.Text = (" ");
Controls.Add(s);
l.Visible = false;
p.Visible = false;
q.Visible = false;
t.Visible = false;
r.Visible = false;
s.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
int a, b, c;
a = Convert.ToInt32(t.Text);
b = Convert.ToInt32(r.Text);
c = a + b;
s.Text = c.ToString();
}
private void button5_Click(object sender, EventArgs e)
{
l.Visible = true;
p.Visible = true;
q.Visible = true;
t.Visible = true;
r.Visible = true;
s.Visible = true;
}
private void button2_Click(object sender, EventArgs e)
{
int a, b, c;
a = Convert.ToInt32(t.Text);
b = Convert.ToInt32(r.Text);
c = a - b;
s.Text = c.ToString();
}
20

private void button3_Click(object sender, EventArgs e)


{
int a, b, c;
a = Convert.ToInt32(t.Text);
b = Convert.ToInt32(r.Text);
c = a * b;
s.Text = c.ToString();
}
private void button4_Click(object sender, EventArgs e)
{
int a, b;
float c;
a = Convert.ToInt32(t.Text);
b = Convert.ToInt32(r.Text);
c = a / b;
s.Text = c.ToString();
}
}
}

Output :

21

17- PROGRAM TO CHANGE DIFFERENT TYPE COLOR


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Color
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ColorDialog c = new ColorDialog();
c.ShowDialog();
this.BackColor = c.Color;
textBox1.ForeColor = c.Color;
}
}
}

Output :

22

18- PROGRAM TO CALCULATE BILL


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Bill
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("Chinees");
comboBox1.Items.Add("South Indian");
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "Chinees")
{
listBox1.Items.Clear();
listBox1.Items.Add("CHOWMEEN");
listBox1.Items.Add("XYZ");
}
if (comboBox1.Text == "South Indian")
{
listBox1.Items.Clear();
listBox1.Items.Add("IDLI");
listBox1.Items.Add("DOSHA");
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
tbqty.Text = string.Empty;
tbamount.Text = string.Empty;
if (listBox1.SelectedItem.ToString() == "CHOWMEEN")
tbrate.Text = Convert.ToString(80);
else if (listBox1.SelectedItem.ToString() == "XYZ")
23

tbrate.Text = Convert.ToString(100);
else if (listBox1.SelectedItem.ToString() == "IDLI")
tbrate.Text = Convert.ToString(60);
else if (listBox1.SelectedItem.ToString() == "DOSHA")
tbrate.Text = Convert.ToString(70);
else
tbrate.Text = string.Empty;
}
private void button1_Click(object sender, EventArgs e)
{
if (tbamount.Text != "")
listBox2.Items.Add(tbamount.Text);
else
MessageBox.Show("Please first calculate amount");
}
private void button2_Click(object sender, EventArgs e)
{
int sum = 0;
foreach (string n in listBox2.Items)
{
sum = sum + Convert.ToInt32(n);
}
tbtotal.Text = "Rs. "+sum.ToString()+" Only";
}
private void tbqty_TextChanged(object sender, EventArgs e)
{
if (tbqty.Text != "")
{
int a, b, c;
a = Convert.ToInt32(tbrate.Text);
b = Convert.ToInt32(tbqty.Text);
c = a * b;
tbamount.Text = c.ToString();
}
else
tbamount.Text = string.Empty;
}
private void button5_Click(object sender, EventArgs e)
{
tbqty.Text = string.Empty;
tbamount.Text = string.Empty;
listBox2.Items.Clear();
tbtotal.Text = string.Empty;
}
24

private void tbqty_Leave(object sender, EventArgs e)


{
listBox2.Items.Add(tbamount.Text);
}
}
}

Output :

25

18 PROGRAM TO LISTBOX
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ListBoxDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox2.Items.Add(listBox1.SelectedItem.ToString());
listBox1.Items.Remove(listBox1.SelectedItem);
listBox2.Sorted = true;
}
private void button2_Click(object sender, EventArgs e)
{
listBox1.Items.Add(listBox2.SelectedItem.ToString());
listBox2.Items.Remove(listBox2.SelectedItem);
}
private void button3_Click(object sender, EventArgs e)
{
foreach(string n in listBox1.Items)
{
listBox2.Items.Add(n.ToString());
}
listBox1.Items.Clear();
}
private void button4_Click(object sender, EventArgs e)
{
foreach (string n in listBox2.Items)
{
listBox1.Items.Add(n.ToString());
}
26

listBox2.Items.Clear();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Sorted = true;
}
}
}

Output :

27

20 PROGRAM TO IMAGE SHOW


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace picture
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Image = new Bitmap(@"C:\Users\BRAMHA\Pictures\New folder\B.jpg");
pictureBox1.Visible = true;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
pictureBox1.Visible = false;
}
}
} Output

28

You might also like