Your Ad Here

Tuesday, July 1, 2008

Simple Mathematical Operations On Two Numbers

/* Program in C# to Input Two Double numbers from the user and find the Addition, Subtraction, Multiplication, Division, Remainder and factorial of the two numbers. */


Click To View Full Size



// Form1.designer.cs

namespace Mathematical_Operations
{
partial class Form1
{
/// < summary>
/// Required designer variable.
/// < /summary>
private System.ComponentModel.IContainer components = null;

/// < summary>
/// Clean up any resources being used.
/// < /summary>
/// < param name="disposing">true if managed resources should be disposed; otherwise, false.< /param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// < summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// < /summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 49);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(87, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Enter 1st number";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 82);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(93, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Enter 2nd Number";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(133, 42);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 2;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(133, 75);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(58, 13);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(124, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Mathematical Operations";
//
// button1
//
this.button1.Location = new System.Drawing.Point(15, 115);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(68, 23);
this.button1.TabIndex = 5;
this.button1.Text = "ADD";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(91, 115);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(68, 23);
this.button2.TabIndex = 6;
this.button2.Text = "Subtract";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(165, 115);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(68, 23);
this.button3.TabIndex = 7;
this.button3.Text = "Division";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(15, 153);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(68, 23);
this.button4.TabIndex = 8;
this.button4.Text = "Remainder";
this.button4.UseVisualStyleBackColor = true;
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(91, 153);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(68, 23);
this.button5.TabIndex = 9;
this.button5.Text = "Factorial";
this.button5.UseVisualStyleBackColor = true;
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(165, 153);
this.button6.Name = "button6";
this.button6.Size = new System.Drawing.Size(68, 23);
this.button6.TabIndex = 10;
this.button6.Text = "Exit";
this.button6.UseVisualStyleBackColor = true;
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(94, 196);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(0, 13);
this.label4.TabIndex = 11;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(247, 231);
this.Controls.Add(this.label4);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Mathmatical Operations";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Label label4;
}
}



//Form1.cs
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 Mathematical_Operations
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
double a, b;
a = Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);

label4.Text = Convert.ToString(a + b);
}

private void button2_Click(object sender, EventArgs e)
{
double a, b;
a = Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);

label4.Text = Convert.ToString(a - b);
}

private void button3_Click(object sender, EventArgs e)
{
double a, b;
a = Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);

label4.Text = Convert.ToString(a / b);
}

private void button4_Click(object sender, EventArgs e)
{
double a, b;
a = Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);

label4.Text = Convert.ToString((int)a % (int)b);
}

private void button5_Click(object sender, EventArgs e)
{
double a, b;
a = Convert.ToDouble(textBox1.Text);
b = Convert.ToDouble(textBox2.Text);
int fact=1;
for (int i = 1; i < = a; i++)
fact *= i;
a = fact;
fact=1;
for(int i=1;i< b;i++)
fact *= i;
label4.Text = "1st Number : "+a+"\n2nd Number :"+fact;
}

private void button6_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}

Total Of Student's Marks

/* Simple Program in C# (for beginners) to input the name from the user and his marks in two subject and find the total in the two subjects. */
Click To View Full Size



//Form1.designer.cs
namespace Student_Marks
{
partial class Form1
{
///
/// Required designer variable.
///

private System.ComponentModel.IContainer components = null;

///
/// Clean up any resources being used.
///

/// true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.label5 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(15, 56);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(75, 13);
this.label1.TabIndex = 0;
this.label1.Text = "Student Name";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(15, 102);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(42, 13);
this.label2.TabIndex = 1;
this.label2.Text = "Marks1";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(15, 148);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(42, 13);
this.label3.TabIndex = 2;
this.label3.Text = "Marks2";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(15, 194);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(37, 13);
this.label4.TabIndex = 3;
this.label4.Text = "Result";
//
// button1
//
this.button1.Location = new System.Drawing.Point(18, 227);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(61, 23);
this.button1.TabIndex = 4;
this.button1.Text = "Calculate";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(84, 227);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(54, 23);
this.button2.TabIndex = 5;
this.button2.Text = "Clear";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 53);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(100, 20);
this.textBox1.TabIndex = 6;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(96, 95);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(100, 20);
this.textBox2.TabIndex = 7;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(96, 141);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(100, 20);
this.textBox3.TabIndex = 8;
//
// textBox4
//
this.textBox4.Enabled = false;
this.textBox4.Location = new System.Drawing.Point(96, 187);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(100, 20);
this.textBox4.TabIndex = 9;
//
// button3
//
this.button3.Location = new System.Drawing.Point(143, 227);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(54, 23);
this.button3.TabIndex = 10;
this.button3.Text = "Exit";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(52, 18);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(114, 13);
this.label5.TabIndex = 11;
this.label5.Text = "Display Student Result";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(215, 266);
this.Controls.Add(this.label5);
this.Controls.Add(this.button3);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label4);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Student Report";
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label5;
}
}




// Form1.cs
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 Student_Marks
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button3_Click(object sender, EventArgs e)
{
Application.Exit();
/*Form2 form = new Form2();
form.Show();*/
}

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

private void button1_Click(object sender, EventArgs e)
{

int marks1 = Convert.ToInt32(textBox2.Text);
int marks2 = Convert.ToInt32(textBox3.Text);
textBox4.Text = Convert.ToString(marks1 + marks2);
}

private void button4_Click(object sender, EventArgs e)
{

}
}
}

Sunday, June 15, 2008

Implementing Polymorphism

/* The given C sharp example decalres abstract class Shape
* that implements polymorpism by overloading and
* overridding methods. The clas Shape2 consists
* of a virtual method ShapeType(). The method
* CalculateArea() is implemented twice by having
* different signatures and different return types.
* The class Square inherits the base class Shape2
* and overrides the base class method called ShapeType().
* The main() method creates an instance of the derieved
* class Square and the base class Shape2. the instance
* of the base class Shape2 invokes the method
* CalculateArea(). Depending on the parameter that
* the method CalcualteArea() takes, the apropiate
* method is called.
*/
using System;

namespace Inherit
{
class Shape2
{
public virtual void ShapeType()
{
Console.WriteLine("This message will be used to display type of the shape");
}
public int CalculateArea(int side)
{
return side * side;
}
public double CalculateArea(double baseBreadth, double height)
{
return 05 * baseBreadth * height;
}
}
class Square :Shape2
{
public override void ShapeType()
{
Console.WriteLine("A square is a Polygon");
}
public static void Main(string[] args)
{
Square sqr = new Square();
sqr.ShapeType();
Console.WriteLine("Area IS : "+sqr.CalculateArea(6));
}
}
}

//Output

//A square is a Polygon
//Area IS : 36

Saturday, June 14, 2008

Multi level inheritance

/* Write a program in C sharp on parameteried
construtor in multilevel inheritance*
*/
using System;

namespace Inherit
{
class Metals
{
string _metalType;
public Metals(String type)
{
_metalType = type;
Console.WriteLine("Metal\t\t:" + _metalType);
}
}

class SteelCompany : Metals
{
string _grade;
public SteelCompany(string grade) : base("Steel")
{
_grade = grade;
Console.WriteLine("Grade\t\t:" + _grade);
}
}
class Automobiles : SteelCompany
{
string _part;
public Automobiles(string part): base("Cast Iron")
{
_part = part;
Console.WriteLine("Part\t\t:" + _part);
}
public static void Main()
{
Automobiles auto = new Automobiles("Mercedes");
}
}
}

//Output

//Metal :Steel
//Grade :Cast Iron
//Part :Mercedes

Multilevel Inhetitance 2

/* C# program to implemmet multi level inheritance.
This program demonstrates how base class constructors are inherited using multilevel inheritance. */

using System;

namespace Inherit
{
class Shape
{
public Shape()
{
Console.WriteLine("Constructor of base class Shape");
}
}
class Polygon : Shape
{
public Polygon()
{
Console.WriteLine("Constructor of Base class Polygon");
}
}
class Quad : Polygon
{
public Quad()
{
Console.WriteLine("Contructor of class Quad");
}
public static void Main(string[] args)
{
Quad obj= new Quad();
}
}
}

//Output

//Constructor of base class Shape
//Constructor of Base class Polygon
//Contructor of class Quad

Multilevel Inheritance

/* Program in C# for implementation of multiway inheritance */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Inherit
{
class One:Mammal
{
public void Noise()
{
Console.WriteLine("Dog Barks");
}

static void Main(string[] args)
{
One obj = new One();
obj.Eat();
obj.feature();
obj.Noise();
}
}

class Animal
{
public void Eat()
{
Console.WriteLine("Every Animal Eats Something");
}
}

class Mammal : Animal
{
public void feature()
{
Console.WriteLine("Mammal Gives birth to young ones");
}
}
}
//Output

//Every Animal Eats Something
//Mammal Gives birth to young ones
//Dog Barks

Tuesday, June 3, 2008

Matrix Operations - Addition, Subtraction, Multiplication

/* Simple C sharp program for adding, subtracting and multiplyilng two matrices.
The program takes inputs for rows and columns of the two matrices seperately and then calculates the following :

1. Addition
2. Subtraction
3. Multiplication.

Functions have been created for addition, subtraction, multiplication and display of the matrices. The program using OOPs is posted seperately. The Functions and variables have to be declared static.

*/

using System;

namespace Array_Pgm
{

class MatrixCalc
{
static int i, j;

static void addMatrix(int[,] A, int[,] B, int m, int n)
{
int[,] C = new int[10, 10];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
C[i, j] = A[i, j] + B[i, j];
}
display(C, m, n);
}

static void subMatrix(int[,] A, int[,] B, int m, int n)
{
int[,] C = new int[10, 10];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
C[i, j] = A[i, j] - B[i, j];
}
display(C, m, n);
}

static void display(int[,] A, int m, int n)
{
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
Console.Write(A[i, j] + "\t");
Console.WriteLine();
}
}

static void mulMatrix(int[,]A,int [,]B,int m,int n)
{
int [,]C = new int[10,10];
for(i=0;i< m;i++)
{
for(j=0;j< n;j++)
{
C[i,j] = 0;
for(int k=0;k< n;k++)
{
C[i,j] = C[i,j] + A[i,k] * B[k,j];
}
}
}
display(C, m, n);
}

public static void Main(string[] args)
{
// Input First Matrix say A;
int m, n;
Console.Write("Enter No Of Roes And Columns Of Matrix A : ");
m =Convert.ToInt16(Console.ReadLine());
n =Convert.ToInt16(Console.ReadLine());
int[,] A = new int[10, 10];
Console.Write("\nEnter The First MNatrix : ");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
A[i, j] =Convert.ToInt16(Console.ReadLine());
}

// Input Second Matrix say B;
int p, q;
Console.Write("Enter No Of Rows And Columns Of Matrix B :");
p =Convert.ToInt16(Console.ReadLine());
q =Convert.ToInt16(Console.ReadLine());
int[,] B = new int[10, 10];
Console.Write("\nEnter The Second Matrix:");
for (i = 0; i < p; i++)
{
for (j = 0; j < q; j++)
B[i, j] = Convert.ToInt16(Console.ReadLine());
}
Console.Clear();

// Display The Two Matrixes

Console.WriteLine("\nMatrix A : ");
display(A, m, n);

Console.WriteLine("\nMatrix B: ");
display(B, p, q);

// Menu
Console.WriteLine("**** MENU For Matrix Opearations *****");
Console.WriteLine(" 1. Addition");
Console.WriteLine(" 2. Subtraction");
Console.WriteLine(" 3. Multiplication");
Console.WriteLine(" 4. Exit");
Console.WriteLine("Enter Your option");
int choice = Convert.ToInt16(Console.ReadLine());

switch (choice)
{
case 1:
if (m == p && n == q)
{
Console.WriteLine("Addition ");
addMatrix(A, B, m, n);
}
else
Console.WriteLine("ERROR !!!!!! Rows and Columns Of Both martixes should be same");
break;

case 2:
if (m == p && n == q)
{
Console.WriteLine("Subtraction ");
subMatrix(A, B, m, n);
}
else
Console.WriteLine("ERROR !!!!!! Rows and Columns Of Both martixes should be same");
break;

case 3:
if (n == p)
{
Console.WriteLine("Multiplication: ");
mulMatrix(A, B, m, q);
}
else
Console.WriteLine("ERROR !!!!!! Column of First matrix and Row Of Second Matrix should be same");
break;

case 4:
Console.Beep(1000, 1000);
break;
/* default:
Console.WriteLine("Error");*/
}
}
}
}

Friday, May 30, 2008

Display Current Data And Time

/* This program displays the words “Hello World!” on the screen,
along with the current date and time */

class Hello
{
public static void Main()
{
// display “Hello World!” on the screen
System.Console.WriteLine(“Hello World!”);
// display the current date and time
System.Console.WriteLine(“The current date and time is “ +
System.DateTime.Now);
}
}

Exception Handling

/* Simple Example On Exception Handling. This program is just intended to give you an idea of how an exception is handled by your C# program. */

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

namespace Program1
{
class Program
{
static void Main(string[] args)
{
double a;

try
{
Console.WriteLine(Enter A float Number);
a = Convert.ToDouble(Console.ReadLine());
}
catch (SystemException ex)
{
Console.WriteLine(ex);
}
}
}
}

Exception Handling - Addition Of Two Byte Numbers

/* C sharp program on exception handling. Addition of two byte numbers. */

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

namespace Program1
{
class check
{
public static void Main()
{
byte numOne;
byte numTwo;
byte result;

Console.WriteLine("Byte Size - (0-255)");
Console.Write("Enter a byte number : ");
numOne = Convert.ToByte(Console.ReadLine());
Console.Write("Enter a byte number : ");
numTwo = Convert.ToByte(Console.ReadLine());

try
{
checked
{
result = (byte) (numOne + numTwo);
}
Console.WriteLine("Result : " + result);
}

catch (ArithmeticException ex)
{
Console.WriteLine(ex);
}
}
}
}

Saturday, May 24, 2008

Negate the positive Elements of The Array

// C# program to Negate the positive Elements of The Array

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

namespace Step2
{
class negate
{
public static void Main()
{
int[] a = new int[10];
for (int i = 0; i < 10; i++)
{
a[i] = Convert.ToInt16(Console.ReadLine());
if (a[i] > 0)
a[i] = -a[i];
}
Console.WriteLine("Elements:");
for (int i = 0; i < 10; i++)
{
Console.WriteLine(a[i]);
}
}
}
}

Grestest Of Three Numbers

// Greater Of Three Numbers

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

namespace Step2
{
class Program
{
static void Main(string[] args)
{
long a, b,c;
start:
try
{

Console.WriteLine("Enter Three Nos");
a = Convert.ToInt64(Console.ReadLine());
b = Convert.ToInt64(Console.ReadLine());
c = Convert.ToInt64(Console.ReadLine());

if (a > b && a > c)
Console.WriteLine("{0} is greater ", a);
else if (b > c && b > a)
Console.WriteLine("{0} is greater", b);
else
Console.WriteLine("{0} is Greater", c);
}

catch (Exception e)
{
Console.WriteLine(e.Message);
goto start;
}
}
}
}

Division Of Two Numbers

/*** C# program to divide two numbers **/

using System;

namespace Program1
{
class except
{
static void Main(string[] args)
{
double a,b,ans;

Console.WriteLine("Enter A Number");
a = Convert.ToDouble(Console.ReadLine());

Console.WriteLine("Enter Another Number");
b = Convert.ToDouble(Console.ReadLine());

ans = a / b;

Console.WriteLine("Answer : " + ans);
}
}
}

Finding Simple Interest

using System;
namespace Interest
{
class Program
{
static void Main(string[] args)
{
int year;
double princ_amt,rate, interest, total_amt;
Console.Write("Enter The Principle Amount : ");
princ_amt = Convert.ToDouble(Console.ReadLine());

Console.Write("Enter The Term : ");
year = Convert.ToInt16(Console.ReadLine());

Console.Write("Enter The Rate Of interest : ");
rate = Convert.ToDouble(Console.ReadLine());

interest = princ_amt * year * rate / 100;
total_amt = princ_amt + interest;

Console.WriteLine("\n----------------------------------------");
Console.WriteLine("Interest : {0} Total Amount : {1}", interest, total_amt);
Console.WriteLine("----------------------------------------");

}
}
}

Friday, May 23, 2008

First Program

using System;

namespace MyFirstPrograms
{
class Program
{
static void Main(string[] args)
{
string name;
Console.Write("What is your name: ");
name = System.Console.ReadLine();

Console.WriteLine("Welcome "+name+" to Your First C# Program!");
}
}
}