Journal C
Journal C
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace hello
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello ");
}
}
}
Output :
2. Write a console application program to demonstrate switching ,looping ,branching
statement.
Switching statement
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace switching
{
class Program
{
static void Main(string[] args)
{
int day = 4;
switch (day)
{
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;
}
}
}
}
Output :
Lopping statement
Code
For loop:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace forloop
{
class Program
{
static void Main(string[] args)
{
for (int i = 0; i< 5; i++)
{
Console.WriteLine(i);
}
}
Output:
While loop :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace whileloop
{
class Program
{
static void Main(string[] args)
{
int i = 0;
while (i< 5)
{
Console.WriteLine(i);
i++;
}
}
}
}
Output :
Branching statement :
If-else :
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ifelsestate
{
class Program
{
static void Main(string[] args)
{
int time = 22;
if (time < 10)
{
Console.WriteLine("Good morning.");
}
else if (time < 20)
{
Console.WriteLine("Good day.");
}
else
{
Console.WriteLine("Good evening.");
Console.Readline();
}
}
}
}
Output :
3.write a console application for swapping of 2 numbers using pass by value.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace swapping
{
class Program
{
static void Main(string[] args)
{
int a = 5, b = 10;
Console.WriteLine("Before swap a= " + a + " b= " + b);
a = a * b;
b = a / b;
a = a / b;
Console.Write("After swap a= " + a + " b= " + b);
Console.Readline();
}
}
}
Output :
4. write a console application for swapping of 2 numbers using pass by reference.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace passbyreference
{
class Program
{
public void swap(ref int x, ref int y)
{
int temp;
temp = x;
x = y;
y = temp;
}
static void Main(string[] args)
{
Program n = new Program();
int a = 100;
int b = 200;
Console.ReadLine();
}
}
}
Output:
5.write a C# program that uses explicit keyword.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace explicitprg
{
class Program
{
static void Main(string[] args)
{
int num = 23;
object obj = num;// implicit conversion
int i = (int)obj;// explicit conversion
Console.WriteLine("Value of ob object is :" + obj);
Console.WriteLine("Value of i is:"+i);
Console.ReadLine();
}
}
}
Output :
6.write a C# program that uses implicit keyword.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace implicitprg
{
class Program
{
static void Main(string[] args)
{
int num = 23;
object obj = num;// implicit conversion
int i = (int)obj;// explicit conversion
Console.WriteLine("Value of ob object is :" + obj);
Console.WriteLine("Value of i is:"+i);
Console.ReadLine();
}
}
}
Output :
7.write C# program to display factorial of number.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace factnum
{
class Program
{
static void Main(string[] args)
{
int i, number, fact;
Console.WriteLine("Enter the Number");
number = int.Parse(Console.ReadLine());
fact = number;
for (i = number - 1; i>= 1; i--)
{
fact = fact * i;
}
Console.WriteLine("\nFactorial of Given Number is: " + fact);
Console.ReadLine();
}
}
}
Output :
8. write C# program to display prime factors of entered number.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace primefactor
{
class Program
{
static void Main(string[] args)
{
int n, i;
Console.WriteLine("Enter the Number:");
n = int.Parse(Console.ReadLine());
Console.WriteLine("Factors:");
for (i = 1; i<= n; i++)
{
if (n % i == 0)
{
Console.WriteLine(i);
}
}
Console.ReadLine();
}
}
}
Output :
9.write C# program check entered number is even or odd.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace evenorodd
{
class Program
{
static void Main(string[] args)
{
int i;
Console.Write("Enter a Number : ");
i = int.Parse(Console.ReadLine());
if (i % 2 == 0)
{
Console.Write("Entered Number is an Even Number");
Console.ReadLine();
}
else
{
Console.Write("Entered Number is an Odd Number");
Console.ReadLine();
}
}
}
}
Output :
10.write C# program to demonstrate array.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace demonstrate
{
class Program
{
public class GFG
{
int x = 50;
int pos = 5;
namespace multilevelinherit
{
class A
{
public void msg()
{
Console.WriteLine("Yashwantrao Chavan Mahavidyalya ");
}
}
class B : A
{
public void info()
{
Console.WriteLine("UrunIslampur");
}
}
class C : B
{
public void display()
{
Console.WriteLine("Tal.Walwa,Dist.Sangli");
}
}
class Program
{
static void Main(string[] args)
{
C objc = new C();
objc.msg();
objc.info();
objc.display();
Console.ReadLine();
}
}
}
Output :
Hierarchical inheritance
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace hierarchicalinheritance
{
class A
{
public void msg()
{
Console.WriteLine("this is a class method");
}
}
class B : A
{
public void info()
{
Console.WriteLine("this is b class method");
}
}
class C : A
{
public void display()
{
Console.WriteLine("this is c class method");
}
}
class D : A
{
public void show()
{
Console.WriteLine("this is d class method");
}
}
class Program
{
static void Main(string[] args)
{
B objb = new B();
C objc = new C();
D objd = new D();
objb.msg();
objb.info();
objc.msg();
objc.display();
objd.msg();
objd.show();
Console.ReadLine();
}
}
}
Output :
12.Write C# program to demonstrate interface.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace multipleinterface
{
interface calc1
{
int add(int a, int b);
}
interface calc2
{
int sub(int x, int y);
}
class Calculation : calc1, calc2
{
public int result1;
public int add(int a, int b)
{
return result1 = a + b;
}
public int result2;
public int sub(int x, int y)
{
return result2 = x - y;
}
}
class Program
{
static void Main(string[] args)
{
Calculation c = new Calculation();
c.add(8, 2);
c.sub(20, 10);
Console.WriteLine("Multiple Inheritance concept Using Interfaces :\n ");
Console.WriteLine("Addition: " + c.result1);
Console.WriteLine("Substraction: " + c.result2);
Console.ReadKey();
}
}
}
Output :
13.Write C# program to demonstrate abstract class.
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace abstractclass
{
abstract class areaclass
{
abstract public int area();
}
class square :areaclass
{
int side = 0;
public square(int n)
{
side = n;
}
public override int area()
{
return side * side;
}
}
class Program
{
static void Main(string[] args)
{
square S =new square(6);
Console.WriteLine("area=" + S.area());
Console.ReadLine();
}
}
}
Output: