- Days_Week
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int num;
Console.WriteLine("Enter a number between 1 to 7");
num = Convert.ToInt32(Console.ReadLine());
switch (num)
{
case 1:
Console.WriteLine("Monday");
break;
case 2:
Console.WriteLine("Tuesday");
break;
case 3:
Console.WriteLine("Wednesday");
break;
case 4:
Console.WriteLine("Thursday");
break;
case 5:
Console.WriteLine("Friday");
break;
case 6:
Console.WriteLine("Saturday");
break;
case 7:
Console.WriteLine("Sunday");
break;
default:
Console.WriteLine("You have entered an invalid number");
break;
}
Console.ReadLine();
}
}
}
- divisibleby 5 :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a ;
Console.WriteLine("Enter any number");
a = Convert.ToInt32(Console.ReadLine());
if (a % 5 == 0)
{
Console.WriteLine("The number is divisible by 5");
}
else
{
Console.WriteLine("The number is not divisible by 5");
}
Console.ReadLine();
}
}
}
- Even_Odd
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, num;
Console.WriteLine("Enter five numbers");
for (i = 0; i <= 4; i++)
{
num = Convert.ToInt32(Console.ReadLine());
if (num % 2 == 0)
{
Console.WriteLine("This number is EVEN");
}
else
{
Console.WriteLine("This number is ODD");
}
}
Console.ReadLine();
}
}
}
- Genric
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class classData<T>
{
public T data;
public T value
{
get
{
return this.data;
}
set
{
this.data = value;
}
}
}
class Test
{
static void Main(string[] args)
{
classData<string> name = new classData<string>();
name.value = ".net";
classData <float> version = new classData<float>();
version.value = 4.5F;
Console.WriteLine(name.value);
Console.WriteLine(version.value);
}
}
}
- Hello Print :-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello");
Console.ReadLine();
}
}
}
- inheritance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Base
{
public Base()
{
Console.WriteLine("Constructor of base class");
}
~Base()
{
Console.WriteLine("Destructor of Base");
}
}
class Derived : Base
{
public Derived()
{
Console.WriteLine("Constructor of Derived");
}
~Derived()
{
Console.WriteLine("Destructor of Derived");
}
}
class BaseDrived
{
static int Main(string[] args)
{
Derived obj = new Derived();
return 0;
}
}
- Largest_among_10Nums
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, num=0, large=0;
Console.WriteLine("Enter 10 +ve numbers");
for (i = 0; i <= 9; i++)
{
num = Convert.ToInt32(Console.ReadLine());
if (num > large)
{
large = num;
}
}
Console.WriteLine("The largest number entered is = " + large);
Console.ReadKey();
}
}
}
- lyfcircle
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Destructors
{
class Calculator
{
static int number1, number2, total;
public void AddNumber()
{
total = number1 + number2;
Console.WriteLine("The Result is {0}", total);
}
Calculator()
{
number1 = 20;
number2 = 30;
total = 0;
Console.WriteLine("Constructor Invoked");
}
~Calculator()
{
Console.WriteLine("Destructor Invoked ");
}
static void Main(string[] args)
{
Calculator c1 = new Calculator();
c1.AddNumber();
Console.ReadLine();
}
Console.ReadKey();
}
}
- Num_Pat1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("Enter the number of rows");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write("1");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
- Num_Pat2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, j, n;
Console.WriteLine("Enter the number of rows");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
for (j = 1; j <= i; j++)
{
Console.Write(j);
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
- Num_Pat3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, j, n, k = 1;
Console.WriteLine("Enter the number of rows");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
for (j = i; j <= 2 * i - 1; j++)
{
Console.Write(k);
k++;
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
- Num_Pat4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, j, k, n,p=1;
Console.WriteLine("Enter the number of rows");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
for (j = 1; j <= n - i; j++)
{
Console.Write(" ");
}
for (k = 1; k <= 2 * i - 1; k++)
{
Console.Write(p);
p++;
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
- object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Calc
{
class Calculator
{
int num1, num2, total;
public void initialize()
{
num1 = 10;
num2 = 20;
}
public void addnum()
{
total = num1 + num2;
}
public void displaynum()
{
Console.WriteLine(" The total is :" + total);
}
static void Main(string[] args)
{
Calculator cl = new Calculator();
cl.initialize();
cl.addnum();
cl.displaynum();
Console.ReadLine();
}
}
}
- Pro_Div_Mod_2Nums
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b, pro, div, mod;
Console.WriteLine("Enter two numbers");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
pro = a * b;
div = a / b;
mod = a % b;
Console.WriteLine("The Product of the numbers is = " + pro);
Console.WriteLine("The Division of the numbers is = " + div);
Console.WriteLine("The Modulus of the numbers is = " + mod);
Console.ReadLine();
}
}
}
- Sum_Avg_5Nums
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int a, b, c, d, e, sum;
float avg;
Console.WriteLine("Enter Five Numbers");
a = Convert.ToInt32(Console.ReadLine());
b = Convert.ToInt32(Console.ReadLine());
c = Convert.ToInt32(Console.ReadLine());
d = Convert.ToInt32(Console.ReadLine());
e = Convert.ToInt32(Console.ReadLine());
sum = a + b + c + d + e;
avg = sum / 5;
Console.WriteLine("The Sum of numbers is =" + sum);
Console.WriteLine("The Average of numbers is =" + avg);
Console.ReadLine();
}
}
}
No comments:
Post a Comment