Addtion of two numbers
===================
using System;
using System.Collections.Generic;
using System.Text;
namespace proj1
{
class Prog1
{
static void Main(string[] args)
{
int a, b, c;
Console.WriteLine("Enter the value of a");
a = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the value of b");
b = Int32.Parse(Console.ReadLine());
c = a + b;
Console.WriteLine("The value of c is" + c);
Console.WriteLine("\n");
Console.WriteLine("Hellow World");
Console.WriteLine("\n");
}
}
}
Biggest of Two numbers
===================
using System;
using System.Collections.Generic;
using System.Text;
namespace proj1
{
class Prog1
{
static void Main(string[] args)
{
int a, b;
Console.WriteLine("Enter the value of a");
a = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the value of b");
b = Int32.Parse(Console.ReadLine());
if (a > b)
{
Console.WriteLine("a is big");
}
else
{
Console.WriteLine("b is big");
}
}
}
}
Biggest among three numbers
========================
using System;
using System.Collections.Generic;
using System.Text;
namespace proj1
{
class Prog1
{
static void Main(string[] args)
{
int a, b,c;
Console.WriteLine("Enter the value of a");
a = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the value of b");
b = Int32.Parse(Console.ReadLine());
Console.WriteLine("Enter the value of c");
c = Int32.Parse(Console.ReadLine());
if (a > b)
{
if (a > c)
{
Console.WriteLine("a is big");
}
else
{
Console.WriteLine("c is big");
}
}
else
{
if (b > c)
{
Console.WriteLine(" bis big");
}
else
{
Console.WriteLine("c is big");
}
}
}
}
}
==========================================================================================================================
Preprocessor
===========
#define Duch
using System;
using System.Collections.Generic;
using System.Text;
namespace proj1
{
class Prog1
{
static void Main(string[] args)
{
#if Duch
Console.WriteLine("Hallo Word");
#else
Console.WriteLine("Ballo Word");
#endif
}
}
}
======================================================================================================================
Two Class
=========
namespace proj1
{
class Prog1
{
public void fun()
{
Console.WriteLine("Krishnan");
}
class Prog2
{
public static void Main()
{
Prog1 test = new Prog1();
test.fun();
}
}
}
}
==========================================================================================================================
String and input programme
========================
namespace Proj
{
class Prog1
{
static void Main()
{
Console.Write("Enter ur name");
string name;
name = Console.ReadLine();
Console.WriteLine("Hello"+ name);
Console.WriteLine("What is ur age");
name = Console.ReadLine();
Console.WriteLine("Sweet"+ name);
}
}
}
Second
=======
namespace Proj
{
class Prog1
{
static void Main()
{
Console.Write("Enter ur name ");
string name,age;
name = Console.ReadLine();
Console.WriteLine("Hello " + name);
Console.WriteLine("What is ur age ");
name = Console.ReadLine();
Console.WriteLine("Sweet " + name);
Console.WriteLine("What is ur sex");
age = Console.ReadLine();
Console.WriteLine("sex= " + age);
}
}
}
===========================================================================================================================
Using Mathematical functions
========================
namespace Proj
{
class Prog1
{
static void Main()
{
double x;
Console.WriteLine("Enter the value of X");
x = Double.Parse(Console.ReadLine());
double y;
y = Math.Sqrt(x);
Console.WriteLine("Answer= " + y);
}
}
===========================================================================================================================
Just calling a function
==================
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
public static void Main()
{
good();
bad();
normal();
}
static void good()
{
Console.WriteLine("Krishnan");
}
static void bad()
{
Console.WriteLine("Vijayan");
}
static void normal()
{
Console.WriteLine("Nats");
}
}
}
Second
======
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
public static void Main()
{
good();
}
static void good()
{
Console.WriteLine("Krishnan");
bad();
}
static void bad()
{
Console.WriteLine("Vijayan");
normal();
}
static void normal()
{
Console.WriteLine("Nats");
}
}
}
===========================================================================================================================
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
public static void Main()
{
add();
}
static void add()
{
Console.WriteLine("{0}",4>3);
Console.WriteLine("{0}", 4 < 3);
Console.WriteLine("{0}",5<= 3);
Console.WriteLine("{0}", 4 != 3);
Console.WriteLine("{0}", 4 ==4);
}
}
}
Output:
=======
True
False
False
True
True
===========================================================================================================================
Forloop
=======
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
public static void Main()
{
int i;
for (i = 1; i < 5; i++)
{
Console.WriteLine("Krishnan {0}", i);
Console.WriteLine("Krishnan {0}....", i);
}
}
}
}
Output
======
krishnan 1
krishnan 1....
krishnan 2
krishnan 2....
krishnan 3
krishnan 3....
krishnan 4
krishnan 4....
krishnan 5
krishnan 5....
===========================================================================================================================
While
=====
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
public static void Main()
{
int i;
i = 1;
while (i <= 5)
{
Console.WriteLine("HI {0}",i);
i++;
}
}
}
}
hi1
hi2
hi3
..5
===========================================================================================================================
While and Return
=================
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
public static void Main()
{
int i,j;
i = 1;
while (i <= 5)
{
Console.WriteLine("HI {0}",i);
i++;
j = full();
}
}
static int full()
{
int j = 0;
while (j < 5)
{
Console.WriteLine("123");
j++;
}
return 0;
}
}
}
===========================================================================================================================
Multiple Data Types used
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
public static void Main()
{
string s;
int ag;
bool f;
s = "abc";
ag = 100;
f = true;
Console.WriteLine("{0}{2}{1}",s,ag,f);
}
}
}
output
=======
abc true 100
===========================================================================================================================
Passing parameters to function
===============================
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
static void Main()
{
abc(10,false,"Krish");
}
static void abc(int i,bool j,string s)
{
Console.WriteLine("{0} {1} {2}",i,j,s);
}
}
}
===========================================================================================================================
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
static void Main()
{
xxx.abc();
}
class xxx
{
public static void abc()
{
Console.WriteLine("abc");
}
}
}
}
===========================================================================================================================
Multiple class and namespace
========================
using System;
using System.Collections.Generic;
using System.Text;
namespace Proj
{
class Prog1
{
static void Main()
{
abc();
Unit.yyy.bbc();
Prog1.abc();
}
public static void abc()
{
Console.WriteLine("Krishnan");
}
}
namespace Unit
{
class yyy
{
public static void bbc()
{
Console.WriteLine("Some special");
}
}
}
}
==========================================================================================================================
COPY THE CONTENT INTO ONE TEXT IN TO ANOTHER
===========================================
using System;
using System.Collections.Generic;
using System.Text;
class Prog1
{
public static void Main()
{
System.IO.File.Copy("C:\\Documents and Settings\\krishnan\\Desktop\\a.txt","C:\\Documents and Settings\\krishnan\\Desktop\\Ohio\\b.txt",true);
}
}
===========================================================================================================================
using System;
using System.Collections.Generic;
using System.Text;
namespace date
{
class Program
{
static void Main()
{
int a, b, c, f=0, e,t,tot = 0;
a = 8;
b = 4;
c = 1985;
e = a + b + c;
t = e;
for (; t >0; )
{
{
f = t % 10; // reminder
tot = tot + f;
t = ((t - f) / 10); // divident
}
}
Console.Write(tot);
}
}
}
Subscribe to:
Post Comments (Atom)
1 comment:
Great Article
.net training online | C# Online Training | Dot Net Training in Chennai | .Net Training in Chennai | ASP.NET Training | ASP.NET MVC Training | Dot Net Interview Questions | Dot Net Training Institutes in Chennai
Post a Comment