Tuesday 27 November 2012

Student Detail using Database in Windows Application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace windatabase
{
public partial class Form1 : Form
{
OleDbConnection dc = new OleDbConnection();
OleDbCommand dcmd = new OleDbCommand();
OleDbDataReader dr;


public Form1()
{
InitializeComponent();

}

private void clear_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
}

private void Form1_Load(object sender, EventArgs e)
{

dc.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" + "Data Source=E:\\cla.mdb";
dc.Open();
dcmd.Connection = dc;


}

private void save_Click(object sender, EventArgs e)
{
//dataGridView1.Columns.




string name, clas;
int ID=40, age;
name = textBox1.Text;
clas = textBox2.Text;
age = Convert.ToInt16( textBox3.Text);

dcmd.CommandText = "INSERT INTO cla VALUES('"+ID+"','" + name + "','" + clas + "'," +age + ")";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("recordsaved");
}

private void delete_Click(object sender, EventArgs e)
{
int ag;
ag = Convert.ToInt16(textBox4.Text);
dcmd.CommandText = "DELETE * FROM cla WHERE age=" + ag + "";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("Record Deleted");

}

private void search_Click(object sender, EventArgs e)
{
int vv;
vv = Convert.ToInt16(textBox4.Text);
dcmd.CommandText = "SELECT * FROM cla WHERE age=" + vv + "";
dr = dcmd.ExecuteReader();
dr.Read();
string name = dr.GetString(1);
string clas = dr.GetString(2);
int age = dr.GetInt16(3);
textBox1.Text = name;
textBox2.Text = clas;
textBox3.Text = age.ToString();

dr.Close();
}
}
}

Program using List box

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace usinglistbox
{
public partial class Form1 : Form
{
int m1, m2, tot;
public Form1()
{
InitializeComponent();
}

private void clear_Click(object sender, EventArgs e)
{
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
textBox4.Text="";
textBox5.Text = "";

}

private void add_Click(object sender, EventArgs e)
{
m1 = int.Parse(textBox4.Text);
m2 = int.Parse(textBox5.Text);
tot = m1 + m2;

listBox1.Items.Add(textBox1.Text);
listBox2.Items.Add(textBox2.Text);
listBox3.Items.Add(textBox3.Text);
listBox4.Items.Add(textBox4.Text);
listBox5.Items.Add(textBox5.Text);
listBox6.Items.Add(tot);
}

private void remove_Click(object sender, EventArgs e)
{
int x;
x = listBox1.SelectedIndex;
listBox1.Items.RemoveAt(x);
listBox2.Items.RemoveAt(x);
listBox3.Items.RemoveAt(x);
listBox4.Items.RemoveAt(x);
listBox5.Items.RemoveAt(x);
listBox6.Items.RemoveAt(x);


}


}
}

Blood Bank Using Databse in Windoes Application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace examblood
{
public partial class Form1 : Form
{
int i = -1;
OleDbConnection con = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
OleDbDataReader dr;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
con.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0;data source=E:\\blood1.mdb";
con.Open();
cmd.CommandText = "select bgroup from blood1";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr.GetString(0));

}
//dr.Close();
con.Close();
/* con.Open();
cmd.CommandText = "select * from blood1";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = dr.GetInt16(0);
dataGridView1.Rows[i].Cells[1].Value = dr.GetString(1);
dataGridView1.Rows[i].Cells[2].Value = dr.GetInt16(2);
dataGridView1.Rows[i].Cells[3].Value = dr.GetString(3);
}
con.Close();*/
}

private void button1_Click(object sender, EventArgs e)
{

con.Open();

cmd.CommandText = "insert into blood1 values('" + textBox4.Text + "','" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
cmd.Connection = con;
dr = cmd.ExecuteReader();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
con.Close();

}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
//con.Open();
// cmd.CommandText
string s = comboBox1.SelectedItem.ToString();
textBox5.Text = s.ToString();
con.Open();
cmd.CommandText = "select * from blood1 where bgroup='"+s+"'";
cmd.Connection = con;
dr = cmd.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = dr.GetInt16(0);
dataGridView1.Rows[i].Cells[1].Value = dr.GetString(1);
dataGridView1.Rows[i].Cells[2].Value = dr.GetInt16(2);
dataGridView1.Rows[i].Cells[3].Value = dr.GetString(3);
}
con.Close();
}

private void textBox5_TextChanged(object sender, EventArgs e)
{

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
textBox5.Text = dataGridView1.SelectedCells[0].Value.ToString();

}

private void groupBox1_Enter(object sender, EventArgs e)
{

}
}
}

Bank Transaction Using Database in Windows Application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace bankdetails
{
public partial class Form1 : Form
{
int acc, amt,age,i=-1;
string name, branch, z;
OleDbConnection dc = new OleDbConnection();
OleDbCommand dcmd = new OleDbCommand();
OleDbDataReader dr;
public Form1()
{
InitializeComponent();
}

private void CLEAR_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
textBox5.Text = "";
errorProvider1.Clear();

}

private void Form1_Load(object sender, EventArgs e)
{
dc.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" + "Data Source=E:\\bank.mdb";
dcmd.Connection = dc;
dc.Open();
dcmd.CommandText="SELECT acc FROM bank";
dr = dcmd.ExecuteReader();
while (dr.Read())
{
comboBox1.Items.Add(dr.GetInt16(0));
}
dr.Close();
}

private void SAVE_Click(object sender, EventArgs e)
{
if (textBox3.Text == "")
{
errorProvider1.SetError(textBox3, "fill it");
}
else
{

acc = Convert.ToInt16(textBox1.Text);
name = textBox2.Text;
age = Convert.ToInt16(textBox3.Text);
branch = textBox4.Text;
amt = Convert.ToInt16(textBox5.Text);
dcmd.CommandText = "INSERT INTO bank VALUES(" + acc + ",'" + name + "'," + age + ",'" + branch + "'," + amt + ")";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("Record Inserted Successfully");
}
}

private void DELETE_Click(object sender, EventArgs e)
{
z = comboBox1.SelectedItem.ToString();
dcmd.CommandText = "DELETE * FROM bank WHERE acc=" + z + "";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("Record Deleted");
}

private void UPDATE_Click(object sender, EventArgs e)
{
z = comboBox1.SelectedItem.ToString();
//dr.Read();
acc = Convert.ToInt16(textBox1.Text);
name = textBox2.Text;
age = Convert.ToInt16(textBox3.Text);
branch = textBox4.Text;
amt =Convert.ToInt16(textBox5.Text);
dcmd.CommandText = "UPDATE bank SET acc='" + acc + "',name='" + name + "',age=" + age + ",branch='" + branch + "',amt=" + amt + " WHERE acc=" + z + "";
dr = dcmd.ExecuteReader();
dr.Close();
MessageBox.Show("RECORD UPDATED SUCESSFULLY");
}

private void SEARCH_Click(object sender, EventArgs e)
{
z = comboBox1.SelectedItem.ToString();
dcmd.CommandText = "SELECT * FROM bank WHERE acc=" + z + "";
dr = dcmd.ExecuteReader();
dr.Read();
acc = dr.GetInt16(0);
name = dr.GetString(1);
age = dr.GetInt16(2);
branch = dr.GetString(3);
amt = dr.GetInt16(4);
textBox1.Text = acc.ToString();
textBox2.Text = name;
textBox3.Text = age.ToString();
textBox4.Text = branch;
textBox5.Text = amt.ToString();
dr.Close();


}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string s = comboBox1.SelectedItem.ToString();
dcmd.CommandText = "select * from bank where acc=" + s + "";
dr = dcmd.ExecuteReader();
while (dr.Read())
{
i++;
dataGridView1.Rows.Add();
dataGridView1.Rows[i].Cells[0].Value = dr.GetInt16(0);
dataGridView1.Rows[i].Cells[1].Value = dr.GetString(1);
dataGridView1.Rows[i].Cells[2].Value = dr.GetInt16(2);
dataGridView1.Rows[i].Cells[3].Value = dr.GetString(3);
dataGridView1.Rows[i].Cells[4].Value = dr.GetInt16(4);
}
dr.Close();

}
}
}

Transpose Matrix

using System;
using System.Collections.Generic;
using System.Text;

namespace transpose_matrix
{
class mat
{
int[,] a = new int[20, 20];
int i,j,n,m;
public void get()
{
Console.WriteLine("TRANSPOSE MATRIX");
Console.WriteLine("*****************");
Console.WriteLine("Enter the Row Value");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Column Value");
m = int.Parse(Console.ReadLine());
Console.WriteLine("Enter The Elements One by One");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
a[i, j] = new int();
a[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("Given Matrix");
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
Console.Write("{0}\t", a[i, j]);
}
Console.WriteLine();
}
}
public void cal()
{
Console.WriteLine("TRANSPOSE MATRIX");
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
Console.Write("{0}\t", a[j, i]);
}
Console.WriteLine();
}
}
}

class transpose
{
static void Main(string[] args)
{
mat q = new mat();
q.get();
q.cal();

}
}
}

Student Marklist in Console Application

using System;
using System.Collections.Generic;
using System.Text;

namespace stud
{
class student
{
int id,m1,m2,m3,tot,avg;
string name,res,grade;
public void get()
{
Console.WriteLine("Enter the student ID");
id=int.Parse(Console.ReadLine());
Console.WriteLine("Enter the student name");
name=Console.ReadLine();
Console.WriteLine("Enter the Mark1,Mark2,Mark3");
m1=int.Parse(Console.ReadLine());
m2=int.Parse(Console.ReadLine());
m3=int.Parse(Console.ReadLine());
}
public void cal()
{
tot = m1 + m2 + m3;
avg = tot / 3;
if(m1>=45 && m2>=45 && m3>=45)
{
res="pass";
if(avg>=85 && avg<=100)
{
grade="A";
}
else if(avg<=84 && avg>=70)
{
grade="B";
}
else
{
grade="C";
}
}
else
{
res="Fail";
grade="-";
}
}


public void display()
{

Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", id, name, m1, m2, m3, tot, avg,res,grade);
}
}
class stude
{

static void Main(string[] args)
{
int i, n;
student[] s=new student[20];
Console.WriteLine("Enter the no of students");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
s[i] = new student();
s[i].get();
s[i].cal();

}
Console.WriteLine("ID\tNAME\tM1\tM2\tM3\tTOTAL\tAVG\tRESULT\tGRADE");
for (i = 1; i <= n; i++)
{
s[i].display();
}
}
}
}

Matrix Manipulation

using System;
using System.Collections.Generic;
using System.Text;

namespace matrixmanipulation
{
class mat
{
int[,] a=new int[30,30];
int m,n;
int i,j,k;
public void input()
{
Console.WriteLine("Enter the row");
m=int.Parse(Console.ReadLine());
Console.WriteLine("Enter the column");
n=int.Parse(Console.ReadLine());
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{

a[i,j]=int.Parse(Console.ReadLine());
}
}
}
public void getdata(mat m1, mat m2, int ch)
{
switch (ch)
{
case 1:
{
if (m1.m == m2.n)
{
for (i = 1; i <= m1.m; i++)
{
for (j = 1; j <= m2.n; j++)
{
a[i, j] = 0;
for (k = 1; k <= m1.n; k++)
{
a[i, j] = a[i, j] + m1.a[i, k] * m2.a[k, j];
}
}
}
m = m1.m;
n = m2.n;
output();
}
else
{
Console.WriteLine("cant perform");
}
break;


}
case 2:
{
if (m1.m == m2.m && m1.n == m2.n)
{
for (i = 1; i <= m1.m; i++)
{
for (j = 1; j <= m2.n; j++)
{
a[i, j] = m1.a[i, j] + m2.a[i, j];
}
m = m1.m;
n = m2.n;
output();
}
}
else
{
Console.WriteLine("cant perform");
}
break;

}
case 3:
{
if (m1.m == m2.m && m1.n == m2.n)
{
for (i = 1; i <= m1.m; i++)
{
for (j = 1; j <= m2.n; j++)
{
a[i, j] = m1.a[i, j] - m2.a[i, j];
}
m = m1.m;
n = m2.n;
output();
}
}
else
{
Console.WriteLine("cant perform");
}
break;

}
}
}



public void output()
{
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
Console.Write("{0}",a[i,j]);
}
Console.WriteLine("\n");
}
}
}


class Program
{
static void Main(string[] args)
{
mat m1=new mat();
mat m2=new mat();
mat m3=new mat();
int ch=0;
while(ch<4)
{
Console.WriteLine("1.matix multiplication");
Console.WriteLine("2.Addition");
Console.WriteLine("3.Subtrraction");
Console.WriteLine("4.exit");
Console.WriteLine("enter your choice");
ch=int.Parse(Console.ReadLine());
if(ch<4)
{
m1.input();
m2.input();
m3.getdata(m1,m2,ch);
}
}

}
}
}

Matrix Row Sum,Column Sum,Diagonal Sum

using System;
using System.Collections.Generic;
using System.Text;

namespace matrix_row_col_diag_sum
{
class mat
{
int i, j, m, n;
int[,] a = new int[20,20];
int[,] b = new int[20,20];
int[,] c = new int[20,20];
public void get()
{
Console.WriteLine("MATRIX ROW SUM,COLUMN SUM,DIAGONAL SUM");
Console.WriteLine("**************************************");
Console.WriteLine("Enter Row Value");
m = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Column Value");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter Elements one by one");
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
a[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("Given Matrix");
for (i = 1; i <= m; i++)
{
for (j = 1; j <= n; j++)
{
Console.Write("\t{0}",a[i, j]);
}
Console.WriteLine();
}
}
public void row()
{
int r;
for (i = 1; i <= m; i++)
{
r = 0;
for (j = 1; j <= n; j++)
{
r = r + a[i, j];
}
Console.WriteLine("{0} Row Sum={1}", i, r);
}
}
public void col()
{
int c;
for (i = 1; i <= n; i++)
{
c = 0;
for (j = 1; j <= m; j++)
{
c = c + a[j, i];
}
Console.WriteLine("{0} col Sum={1}", i, c);
}
}
public void diag()
{
int d;
d = 0;
if (m == n)
{
for (i = 1; i <= m; i++)
{

for (j = 1; j <= n; j++)
{
if (i == j)
{
d = d + a[i, j];
}

}
}
Console.WriteLine("Diagonal Sum= {0}", d);
}
else
{
Console.WriteLine("Can't Perform Diagonal Sum");
}


}

}
class matsum
{
static void Main(string[] args)
{
mat q = new mat();
q.get();
q.row();
q.col();
q.diag();
}
}
}

Employee Paybill Preparation

using System;
using System.Collections.Generic;
using System.Text;

namespace employee
{
class employ
{
protected int id, basic;
protected string name;
public void getdata()
{
Console.WriteLine("Enter the Employee ID");
id = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Employee Name");
name = Console.ReadLine();
Console.WriteLine("Enter the basic salary");
basic = int.Parse(Console.ReadLine());
}
}
class staff:employ
{
double hra = 0.05, da = 0.04, pf = 0.03, it = 0.05;
double hra1,da1,pf1,it1,az,ad,net;
public void calculate()
{
hra1 = hra * basic;
da1 = da * basic;
pf1 = pf * basic;
it1 = it * basic;
az = (da1 + hra1);
ad = (pf1 + it1);
net = (basic + az - ad);
}
public void display()
{
Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}",id,name,basic,hra1,da1,pf1,it1,net);
}
}
class emp
{

static void Main(string[] args)
{
int i, n;
staff[] s = new staff[20];
Console.WriteLine("Enter the no of Employee");
n = int.Parse(Console.ReadLine());
for (i = 0; i < n; i++)
{
s[i] = new staff();
s[i].getdata();
s[i].calculate();
}
Console.WriteLine("Employee Paybill perparation");
Console.WriteLine("ID\tNAME\tBASIC\tHRA\tDA\tPF\tIT\tNET");

for (i = 0; i < n; i++)
{
s[i].display();
}



}
}
}

Dictionary in console Application

using System;
using System.Collections;
using System.Text;

namespace dictionary
{
class Program
{
static void Main(string[] args)
{
SortedList s = new SortedList();
string name, word;
int ch=0,n;
while (ch < 4)
{
Console.WriteLine("MENU");
Console.WriteLine("1.ADD");
Console.WriteLine("2.SEARCH");
Console.WriteLine("3.DELETE");
Console.WriteLine("4.EXIT");
Console.WriteLine("Enter your Choice");
ch = int.Parse(Console.ReadLine());

switch (ch)
{
case 1:
{
Console.WriteLine("Enter no of words");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the words & meaning one by one");
for (int i = 0; i <= n; i++)
{
word = Console.ReadLine();
name = Console.ReadLine();
s.Add(word, name);
}
Console.WriteLine("words to be added");
foreach (DictionaryEntry elt in s)
{
Console.WriteLine(elt.Key + ":" + elt.Value);
}
break;
}
case 2:
{
Console.WriteLine("Enter the word to be search");
word = Console.ReadLine();
if (s.ContainsKey(word))
Console.WriteLine(word + ":" + s[word]);
else
Console.WriteLine("word not found");
break;
}
case 3:
{
Console.WriteLine("Enter the word to be delete");
word = Console.ReadLine();
if (s.ContainsKey(word))
{
s.Remove(word);
foreach (DictionaryEntry elt in s)
{
Console.WriteLine(elt.Key + ":" + elt.Value);
}
}
else

Console.WriteLine("word not found");
break;

}
}
}


}
}
}

Database in Console Application

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;

namespace Consodatabase
{
class stumark
{
static void Main(string[] args)
{
OleDbConnection dc = new OleDbConnection();
int f = 1,ch;
string reg,name,clas;
int age;
try
{
dc.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;" + "Data Source=f:\\stud.mdb";
dc.Open();
OleDbCommand dcmd = new OleDbCommand();
OleDbDataReader dr;// = dcmd.ExecuteReader();
dcmd.Connection = dc;
while (f == 1)
{
Console.WriteLine("\t1.Add");
Console.WriteLine("\t2.ViewAll");
Console.WriteLine("\t3.Delete");
Console.WriteLine("\t4.Exit");
Console.WriteLine("Enter your choice");
ch = int.Parse(Console.ReadLine());
switch (ch)
{
case 1:
{
Console.WriteLine("Enter Regno");
reg = Console.ReadLine();
Console.WriteLine("Enter Name");
name = Console.ReadLine();
Console.WriteLine("Enter Class");
clas = Console.ReadLine();
Console.WriteLine("Enter Age");
age = int.Parse(Console.ReadLine());
dcmd.CommandText = "INSERT INTO stud VALUES('" + reg + "','" + name + "','" + clas + "'," + age + ")";
dr = dcmd.ExecuteReader();
dr.Close();
break;
}
case 2:
{
dcmd.CommandText = "SELECT * FROM stud";
dr = dcmd.ExecuteReader();
Console.WriteLine("RegNo\tName\tClass\tAge");
while (dr.Read())
{
reg = dr.GetString(0);
name = dr.GetString(1);
clas = dr.GetString(2);
age = dr.GetInt32(3);
Console.WriteLine("{0}\t{1}\t{2}\t{3}", reg, name, clas, age);
}
dr.Close();
break;
}
case 3:
{
Console.WriteLine("Enter reg no to Delete");
string re=Console.ReadLine();
dcmd.CommandText="DELETE * FROM stud WHERE reg='"+re+"'";
dr=dcmd.ExecuteReader();
dr.Close();
break;
}

default:
f = 0;
break;
}
}
}
catch (Exception e)
{
Console.WriteLine("Error" + e.Message);
}
finally
{
dc.Close();
}


}
}
}

Complex Number

using System;
using System.Collections.Generic;
using System.Text;

namespace complex_number
{
class complex
{
int real,img;
public void getdata()
{
Console.WriteLine("Enter the Real Value");
real = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Imaginary Value");
img = int.Parse(Console.ReadLine());
}
public void display()
{
if (img > 0)
{
Console.WriteLine("complex No{0}+{1}i", real, img);
}
else
{
Console.WriteLine("complex No{0}{1}i", real, img);
}
}
public static complex operator +(complex t1, complex t2)
{
complex t4 = new complex();
t4.real = t1.real + t2.real;
t4.img = t1.img + t2.img;
return t4;
}



}
class comp
{
static void Main(string[] args)
{
complex t1 = new complex();
complex t2 = new complex();
complex t3 = new complex();
t1.getdata();
t1.display();
t2.getdata();
t2.display();
t3 = t1 + t2;
t3.display();
}
}
}

Armstrong No Checking

using System;
using System.Collections.Generic;
using System.Text;

namespace armstrong
{
class Program
{
static void Main(string[] args)
{
int n, r, sum = 0;
Console.WriteLine("Entre the no to check");
n = int.Parse(Console.ReadLine());
int n1 = n;
while (n != 0)
{
r = n % 10;
sum = sum + (r * r * r);
n = n / 10;
}
if (sum == n1)
{
Console.WriteLine("the given no {0} is Armstrong no",n1);
}
else
{
Console.WriteLine("the Given no {0} is not an Armstrong No",n1);
}
}
}
}

Sum of All Alternative Numbers

using System;
using System.Collections.Generic;
using System.Text;

namespace sum_of_alternative_numbers
{
class alternat
{
static void Main(string[] args)
{
int[] a = new int[20];
int i,sum = 0,n;
Console.WriteLine("\tSUM OF ALTERNATIVE NUMBERS");
Console.WriteLine("\t***************************");
Console.WriteLine("Enter The Array Limit");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Elements One By One");
for (i = 1; i <= n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("The Alternative Numbers Are");
for (i = 1; i <= n; i = i + 2)
{
Console.WriteLine("{0}", a[i]);
sum = sum + a[i];
}
Console.WriteLine("The Sum of Alternative Numbers={0}", sum);


}
}
}

Search an Element and Find The Occurance

using System;
using System.Collections.Generic;
using System.Text;

namespace search_element_find_position
{
class search
{
static void Main(string[] args)
{
int []a=new int[30];
int n,s,i;
Console.WriteLine("SEARCH AN ELEMENT AND FIND THE OCCURANCE");
Console.WriteLine("*****************************************");
Console.WriteLine("\n Enter the no of Elements");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the elements one by one");
for (i = 1; i <= n; i++)
{
a[i] = int.Parse(Console.ReadLine());

}
Console.WriteLine("The Elements Are");
for (i = 1; i <= n; i++)
{
Console.WriteLine("{0}", a[i]);
}
Console.WriteLine("Enter the Element to Search");
s = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
if (a[i]==s)
{
Console.WriteLine("The Element is in the Set,The Position is{0}",i);
}

}


}
}
}

Maximum & Minimum of n Numbers

using System;
using System.Collections.Generic;
using System.Text;

namespace max_min_of_n_number
{
class Program
{
static void Main(string[] args)
{
int n, i, j,t;
int[] a = new int[50];
Console.WriteLine("\tMAXIMUM & MINIMUM OF N NUMBERS");
Console.WriteLine("\t******************************");
Console.WriteLine("Enter the no of Elements");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Elements one by One");
for (i = 1; i <= n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
for (i = 1; i <= n; i++)
{
for (j = i+1; j <= n; j++)
{
if (a[i] > a[j])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
}
Console.WriteLine("Minimum={0}", a[1]);
Console.WriteLine("Maximum={0}", a[n]);
}
}

}

Count the no of Positive Nagative,zero in an Array

using System;
using System.Collections.Generic;
using System.Text;

namespace count_no_of_possi_negat_zero
{
class count
{
static void Main(string[] args)
{
int[] a = new int[20];
int p = 0, ne = 0, z = 0, n,i;
Console.WriteLine("COUNT THE NO OF POSITIVE,NEGATIVE,ZERO IN AN ARRAY");
Console.WriteLine("***************************************************");
Console.WriteLine("\n Enter the no of Elements");
n=int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Elements one by one");
for (i = 1; i <= n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
for (i = 1; i <= n; i++)
{
if (a[i] > 0)
{
p++;
}
else if (a[i] < 0)
{
ne++;
}
else
{
z++;
}
}
Console.WriteLine("No of Positive={0}", p);
Console.WriteLine("No of Negative={0}", ne);
Console.WriteLine("No of Zeros={0}", z);
}
}
}

Ascending Order

using System;
using System.Collections.Generic;
using System.Text;

namespace ascending_order
{
class ascend
{
static void Main(string[] args)
{
int[] a=new int [20];
int t,i,j,n;
Console.WriteLine("\tASCENDING ORDER");
Console.WriteLine("\t***************");
Console.WriteLine("Enter the no of Elements");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Elements one by One");
for (i = 1; i <= n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("\nASCENDING ORDER");
for (i = 1; i <= n; i++)
{
for (j = i + 1; j <= n; j++)
{
if (a[i] > a[j])
{
t = a[i];
a[i] = a[j];
a[j] = t;
}
}
Console.WriteLine("{0}", a[i]);
}

}
}
}

Sum of N Numbers

using System;
using System.Collections.Generic;
using System.Text;

namespace sumof_n_numbers
{
class sumofn
{
static void Main(string[] args)
{
int n, i,sum=0;
int[] a = new int[30];
Console.WriteLine("\tSUM OF N NUMBERS");
Console.WriteLine("\t****************");
Console.WriteLine("Enter How Many Numbers To Count");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter the Elements One by one");
for (i = 0; i < n; i++)
{
a[i] = int.Parse(Console.ReadLine());
}
for (i = 0; i < n; i++)
{
sum = sum + a[i];
}
Console.WriteLine("The Sum of {0} Number is={1}", n, sum);


}
}
}

Sum of Digit

using System;
using System.Collections.Generic;
using System.Text;

namespace sum_of_digit
{
class sumofdigit
{
static void Main(string[] args)
{
int n,sum=0,m;
Console.WriteLine("\tSUM OF ALL DIGIT");
Console.WriteLine("\t****************");
Console.WriteLine("Enter the Number");
n=int.Parse(Console.ReadLine());
while(n!=0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
Console.WriteLine("Sum of digit={0}",sum);

}
}
}

Prime Number Checking

using System;
using System.Collections.Generic;
using System.Text;

namespace primenumberchecking
{
class primeno
{
static void Main(string[] args)
{
int n,i,p,j=0;
Console.WriteLine("\tPRIME NUMBER CHECKING");
Console.WriteLine("\t**********************");
Console.WriteLine("Enter the Number to Check");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
p = n % i;
if (p == 0)
{
j++;
}
}
if (j == 2)
{
Console.WriteLine("Number {0} is a Prime Number", n);
}
else
{
Console.WriteLine("Number {0} is not a Prime Number", n);
}


}
}
}

NCR

using System;
using System.Collections.Generic;
using System.Text;

namespace ncr
{
class ncr
{
static void Main(string[] args)
{
int n1 = 1,nr1=1, r1 = 1, n,i, r, ans, nr;
Console.WriteLine("\tNCR");
Console.WriteLine("\t****");
Console.WriteLine("Enter The n Value");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter The r Value");
r = int.Parse(Console.ReadLine());
if (n > r)
{
nr = n - r;
for (i = 1; i <= n; i++)
{
n1 = n1 * i;
}
for (i = 1; i <= r; i++)
{
r1 = r1 * i;
}
for (i = 1; i <= nr; i++)
{
nr1 = nr1 * i;
}
ans = n1 / (nr1 * r1);
Console.WriteLine("The NcR Value={0}", ans);
}
else
{
Console.WriteLine("The N Value Must Greater than R Value");
}
}
}
}

Fibonacci Series

using System;
using System.Collections.Generic;
using System.Text;

namespace fibonacci_series
{
class fibo
{
static void Main(string[] args)
{
int f1 = 0, f2 = 1, n,f3,i;
Console.WriteLine("\tFIBONACCI SERIES");
Console.WriteLine("\t****************");
Console.WriteLine("Enter the number");
n = int.Parse(Console.ReadLine());
Console.WriteLine("The Series is");
Console.WriteLine("{0}\n{1}", f1, f2);
for (i = 1; i <= n; i++)
{
f3 = f1 + f2;
f1 = f2;
f2 = f3;
Console.WriteLine("{0}", f3);
}


}
}
}

Factorial Number

using System;
using System.Collections.Generic;
using System.Text;

namespace factorial
{
class fact
{
static void Main(string[] args)
{
int fact = 1, n, i;
Console.WriteLine("\tFACTORIAL NUMBER");
Console.WriteLine("\t******************");
Console.WriteLine("Enter the Number");
n = int.Parse(Console.ReadLine());
if (n == 0)
{
Console.WriteLine("Can't Find Factorial");
}
else
{
for (i = 1; i <= n; i++)
{
fact = fact * i;
}
Console.WriteLine("Answer ={0}", fact);
}
}
}
}

Even Numbber Generation

using System;
using System.Collections.Generic;
using System.Text;

namespace even_number_generation
{
class Program
{
static void Main(string[] args)
{
int n, m,l,i;
Console.WriteLine("EVEN NUMBER GENERATION");
Console.WriteLine("**********************");
Console.WriteLine("Enter The Starting Range");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Enter The Finishing Range");
m = int.Parse(Console.ReadLine());
Console.WriteLine("The Answer is");
l = n % 2;
if (l == 0)
{
for (i = n; i <= m; i=i + 2)
{
Console.WriteLine("{0}", i);
}
}
else
{
for (i = n + 1; i <= m; i=i + 2)
{
Console.WriteLine("{0}", i);
}
}


}
}
}