General C# Programs for Beginners
General C# Programs for Beginners
In this blog we are going to discuss about the basic C# Programming., Below are the some of the programs we are going to discuss. C# Programs are as similar to javascript programming, some keywords are different from Java script.
Solved C# Program Question-Answer follows after the questions.
Program-1
Input a code [C|S|V] and a character .Then find
a)if
the code is ’C’ then find the character is capital or not
b)if
the code is ‘S’ then find the character is small or not
c)if
the code is ‘V’ then find the character is vowel or not
Program-2:
Check
Given Number is Prime or not using C#.
Program-3:
Swap
First and Last Elements of the Given Array
Program-4
Design
a program to Input a Number. Check if it is a positive three digit number or
not
Program-5
Write
a Program to input the height of two students. Print the height of the tallest
person
Program-6
Input
a code [a/b/c] and two numbers
a)Code
is a ,then print biggest of two numbers.
b)Code
is b, then Print smallest of two numbers.
c)Code
is c,then print the sum of the square root of the numbers.
Program-7
A
School has following rules for grading system
a.Below
25-F
b.25
to 45-E
c.45
to 50-D
d.50
to 60-C
E.60
to 80-B
f.Above
80-A
Ask
user to enter marks and print the corresponding grade.
Program-8
It’s a four digit number. If it is divisible by both
3 and 5 find its reverse else ,find the last digit of the number.
Program-9
Input
a radius of a circle.If the area is
double the circumference,then print a message “DOUBLE” else print “not double”
Program-10
A
Student will not be allowed to sit In exam if his/her attendance is less than
75% .Take following input from user
Number
of Classes held
Number
of Classes Attended
And
Print ,Percentage of Class Attended.
Program-11
Write
a program to check whether a entered character is lowercase(a to z) or uppercase
(A to Z).
Program-12
Print
pattern using C#
*
**
***
****
Program-13
Program
to Print duplicate elements of an array.
Program-14
Program
to print Elements of an array in reverse order.
Program-15
Program
to print the elements of an array present on even Position.
Program-16
Program
to Print Odd and Even numbers from an array.
Program-17
ATM Program
Using C#
Program-18
Write
a program to print the area of a rectangle by creating a class named ‘Area’
having two methods.First method named as ‘setDim’ takes length and breadth of
rectangle as parameters and the second method named as ‘getArea’ returns the
area of rectangle.
Program-19
(......Contn)Write a program to print the area of a rectangle by creating a class named ‘Area’ having two methods.First method named as ‘setDim’ takes length and breadth of rectangle as parameters and the second method named as ‘getArea’ returns the area of rectangle.
Solutions for Above C# Programs
PROGRAM-1
Input
a code [C|S|V] and a character .Then find
a)if
the code is ’C’ then find the character is capital or not
b)if
the code is ‘S’ then find the character is small or not
c)if
the code is ‘V’ then find the character is vowel or not
using
System;
namespace
Scope
{
class program
{
public static void Main()
{
Console.WriteLine("Enter the
Character: ");
var a = Console.ReadLine();
Convert.ToString(a);
if (a.Equals("c")||
a.Equals("C"))
{
Console.WriteLine("Enter
the character: ");
var b = Console.ReadLine();
Convert.ToString(b);
if (Char.IsUpper(b,0))
{
Console.WriteLine("The
Character is capital");
}
else
{
Console.WriteLine("The
Character is not capital");
}
}
else if (a.Equals("s") ||
a.Equals("S"))
{
Console.WriteLine("Enter
the character: ");
var c = Console.ReadLine();
Convert.ToString(c);
if (Char.IsLower(c, 0))
{
Console.WriteLine("The
Character is Small");
}
else
{
Console.WriteLine("The
Character is not Small");
}
}
else if (a.Equals("v") ||
a.Equals("V"))
{
Console.WriteLine("Enter
the character: ");
var d = Console.ReadLine();
Convert.ToString(d);
if (d.Equals("a") ||
d.Equals("A") || d.Equals("e") || d.Equals("E")
|| d.Equals("i") || d.Equals("I") ||
d.Equals("o") || d.Equals("O") || d.Equals("u")
|| d.Equals("U"))
{
Console.WriteLine("The
Character is Vowel");
}
else
{
Console.WriteLine("The
Character is not Vowel");
}
}
else
{
Console.WriteLine("Error
Message");
}
}
}
}
PROGRAM-2
Check Given Number is Prime or not using C#.
namespace
Scope
{
class PrimeOrNot
{
public static void Main()
{
Console.WriteLine("Enter the
No: ");
var a =
Convert.ToInt32(Console.ReadLine());
int flag = 0;
for (int i = 2; i < a; i++)
{
if (a % i == 0)
{
Console.WriteLine("It
is not a Prime Number");
flag = 1;
break;
}
}
if (flag == 0)
{
Console.WriteLine("It is a
Prime Number");
}
}
}
}
PROGRAM-3
Swap First and Last Elements of the Given Array
using
System;
namespace
Scope
{
class swapping
{
public static void Main()
{
int[] array = new int[5];
Console.WriteLine("Enter the
Elements: ");
for (int i = 0; i < 5; i++)
{
array[i]=Convert.ToInt32(Console.ReadLine());
}
int a = array[0];
array[0] = array[4];
array[4] = a;
for(int i = 0; i < 5; i++)
{
Console.WriteLine(array[i]);
}
}
}
}
PROGRAM-4
Design a program to Input a Number. Check if it is a positive three digit number or not
using
System;
namespace
Scope
{
class PositiveOrNot
{
public static void Main()
{
Console.WriteLine("Enter the
Number:");
int a=Convert.ToInt32(Console.ReadLine());
if (a > 0 && a > 99)
{
Console.WriteLine("It is a
three digit positive number");
}
else if (a > 0 && a <
100)
{
Console.WriteLine("It is not a
three digit number");
}
else
{
Console.WriteLine("It is
not a Positive Number");
}
}
}
}
PROGRAM-5
Write a Program to input the height of two students. Print the height of the tallest person
using
System;
namespace
Scope
{
class Tallest
{
public static void Main()
{
Console.WriteLine("Enter the
height of Jobin: ");
int
a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the
height of Ajith: ");
int b = Convert.ToInt32(Console.ReadLine());
if(a > b)
{
Console.WriteLine("The
tallest person is Jobin");
}
else
{
Console.WriteLine("The
tallest person is Ajith");
}
}
}
}
PROGRAM-6
Input
a code [a/b/c] and two numbers
a)Code
is a ,then print biggest of two numbers.
b)Code
is b, then Print smallest of two numbers.
c)Code
is c,then print the sum of the square root of the numbers.
using
System;
namespace
Scope
{
class TwoNumbers
{
public static void Main()
{
Console.WriteLine("Enter a/b/c
as Input");
var x=Console.ReadLine();
Convert.ToString(x);
Console.WriteLine("Enter the
numbers");
int
y=Convert.ToInt32(Console.ReadLine());
int
z=Convert.ToInt32(Console.ReadLine());
if (x.Equals("a"))
{
if (y > z)
{
Console.WriteLine("The
Biggest No is:" + y);
}
else
{
Console.WriteLine("The
Biggest No is: " + z);
}
}
else if (x.Equals("b"))
{
if (y > z)
{
Console.WriteLine("The
Smallest No is:" + z);
}
else
{
Console.WriteLine("The
Smallest No is: " + y);
}
}
else if (x.Equals("c"))
{
double i = Math.Sqrt(y);
double j = Math.Sqrt(z);
double k = i + j;
Console.WriteLine("Sum of
Squares of number is " + k);
}
else
{
Console.WriteLine("Wrong
Entry");
}
}
}
}
PROGRAM-7
A
School has following rules for grading system
a.Below
25-F
b.25
to 45-E
c.45
to 50-D
d.50
to 60-C
E.60
to 80-B
f.Above
80-A
Ask
user to enter marks and print the corresponding grade.
using
System;
namespace
Scope
{
class Grading
{
public static void Main()
{
Console.WriteLine("Enter a
number:");
var y=Console.ReadLine();
int x=Convert.ToInt32(y);
if (x >= 80 && x <=
100)
{
Console.WriteLine("A
Grade");
}
else if (x >= 60 && x
< 80)
{
Console.WriteLine("B
Grade");
}
else if (x >= 50 && x
< 60)
{
Console.WriteLine("C
Grade");
}
else if (x >= 45 && x
< 50)
{
Console.WriteLine("D
Grade");
}
else if (x >= 25 && x
< 45)
{
Console.WriteLine("E
Grade");
}
else if (x >= 0 && x
< 25)
{
Console.WriteLine("F
Grade");
}
else
{
Console.WriteLine("Invalid
Data");
}
}
}
}
PROGRAM-8
It’s a four digit number. If it is divisible by both 3 and 5 find its reverse else ,find the last digit of the number.
using
System;
namespace
Scope
{
class ReverseNo
{
public static void Main()
{
int reverse = 0;
Console.WriteLine("Enter a
Number: ");
int x =
Convert.ToInt32(Console.ReadLine());
if (x % 3 == 0 && x % 5 ==
0) {
while (x > 0)
{
int y = x % 10;
reverse = reverse * 10 + y;
x = x / 10;
}
Console.WriteLine("Reversed Number is "+reverse);
}
else
{
x = x % 10;
Console.WriteLine("The last digit
of the number is "+x);
}
}
}
}
PROGRAM-9
Input a radius of a circle.If the area is double the circumference,then print a message “DOUBLE” else print “not double”
using
System;
namespace
Scope
{
class Circle
{
public static void Main()
{
Console.WriteLine("Enter the
radius of the Circle ");
int
r=Convert.ToInt32(Console.ReadLine());
double area = Math.PI * r * r;
double circumference = 2 * Math.PI
* r;
if (area >= 2 * circumference)
{
Console.WriteLine("Double");
}
else
{
Console.WriteLine("Not
Double");
}
}
}
}
PROGRAM-10
A
Student will not be allowed to sit In exam if his/her attendance is less than
75% .Take following input from user
Number
of Classes held
Number
of Classes Attended
And
Print ,Percentage of Class Attended.
using
System;
namespace
Scope
{
class Attendance
{
public static void Main()
{
Console.WriteLine("Number of
classes held:");
int x =
Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Number of
classes attended:");
int y =
Convert.ToInt32(Console.ReadLine());
float z = (y * 100) / x;
Console.WriteLine("Percentage
of class attended:" + z);
if (z >= 75)
{
Console.WriteLine("This
Student is allowed to sit in Exam");
}
else
{
Console.WriteLine("This Student is not
Allowed to sit in Exam");
}
}
}
}
PROGRAM-11
Write a program to check whether a entered character is lowercase(a to z) or uppercase (A to Z).
using
System;
namespace
Scope
{
class Case
{
public static void Main()
{
Console.WriteLine("Enter the
Character ");
var
x=Convert.ToString(Console.ReadLine());
if (char.IsUpper(x, 0))
{
Console.WriteLine("The
Character is Upper Case ");
}
else if(char.IsLower(x, 0))
{
Console.WriteLine("The Character is
Lower Case ");
}
else
{
Console.WriteLine("This is
not a Character ");
}
}
}
}
PROGRAM-12
Print
pattern using C#
*
**
**
*
****
using
System;
namespace
Scope
{
class Pattern
{
public static void Main()
{
for(int i = 0; i < 4; i++)
{
for(int j = 0; j <=i; j++)
{
Console.Write("* ");
}
Console.WriteLine();
}
}
}
}
PROGRAM-13
Program to Print duplicate elements of an array.
using
System;
namespace
Scope
{
class DuplicateElements
{
public static void Main()
{
int[] a = new int[] { 1, 3, 4, 6,
3, 8, 9, 1 };
Console.WriteLine("Duplicate
Elements are ");
for (int i = 0; i < 8; i++)
{
for (int j = i + 1; j < 8;
j++)
{
if (a[i] == a[j])
{
Console.WriteLine(a[j]);
}
}
}
}
}
}
PROGRAM-14
Program to print Elements of an array in reverse order.
using
System;
namespace
Scope
{
class ReverseOrder
{
public static void Main()
{
int[] a = new int[] { 1, 3, 4, 6,
3, 8, 9, 1 };
Console.WriteLine("Reverse
Order is");
for (int i = 7; i >= 0; i--)
{
Console.Write(a[i]+" ");
}
}
}
}
PROGRAM-15
Program to print the elements of an array present on even Position.
using
System;
namespace
Scope
{
class EvenPosition
{
public static void Main()
{
int[] a = new int[] { 1, 3, 4, 6,
3, 8, 9, 1 };
Console.WriteLine("Elements in
Even Position ");
for (int i = 0; i < 8; i++)
{
if (i % 2 == 0)
{
Console.Write(a[i]+" ");
}
}
}
}
}
PROGRAM-16
Program to Print Odd and Even numbers from an array.
using
System;
namespace
Scope
{
class OddOrEven
{
public static void Main()
{
int[] a = new int[] { 1, 3, 4, 6,
3, 8, 9, 1 };
Console.WriteLine("Even No's
are:");
for (int i = 0; i < 8; i++)
{
if (a[i] % 2 == 0)
{
Console.Write(a[i]+"
");
}
}
Console.WriteLine();
Console.WriteLine("Odd No's
are:");
for (int i = 0; i < 8; i++)
{
if (a[i] % 2 == 0)
{
}
else
{
Console.Write(a[i]+" ");
}
}
}
}
}
PROGRAM-17
ATM Program Using C#
using
System;
namespace
Scope
{
class ATM
{
public static void Main()
{
Console.WriteLine("Automated
Teller Machine");
Console.WriteLine("Choose 1
for Withdraw");
Console.WriteLine("Choose 2
for Deposite");
Console.WriteLine("Choose 3
for Check Balance");
Console.WriteLine("Choose 4
for Exit");
Console.WriteLine("Choose the
Operation you want to perform:");
int x =
Convert.ToInt32(Console.ReadLine());
if (x == 1)
{
Console.WriteLine("Enter
money to be withdrawn:");
int y =
Convert.ToInt32(Console.ReadLine());
if (y > 0)
{
Console.WriteLine("Please collect your money");
}
}
else if (x == 2)
{
Console.WriteLine("Enter
money to be deposited");
int z =
Convert.ToInt32(Console.ReadLine());
if (z > 0)
{
Console.WriteLine("Your money has been successfully
deposited");
}
}
else if (x == 3)
{
Console.WriteLine("Balance
: 5500");
}
else if (x == 4)
{
Console.WriteLine("Exiting.....");
}
else
{
Console.WriteLine("Invalid
Input");
}
}
}
}
PROGRAM-18
Write a program to print the area of a rectangle by creating a class named ‘Area’ having two methods.First method named as ‘setDim’ takes length and breadth of rectangle as parameters and the second method named as ‘getArea’ returns the area of rectangle.
using
System;
namespace
Scope
{
public class Area
{
public int setDim()
{
Console.WriteLine("Enter
Length:");
int length =
Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter
Breadth:");
int breadth =
Convert.ToInt32(Console.ReadLine());
int area = length * breadth;
return area;
}
PROGRAM-19
(………Contn)Write a program to print the area of a rectangle by
creating a class named ‘Area’ having two methods.First method named as ‘setDim’
takes length and breadth of rectangle as parameters and the second method named
as ‘getArea’ returns the area of rectangle.
using
System;
namespace
Scope
{
public class Area
{
public int setDim()
{
Console.WriteLine("Enter
Length:");
int length =
Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter
Breadth:");
int breadth =
Convert.ToInt32(Console.ReadLine());
int area = length * breadth;
return area;
}
public void getArea()
{
Console.WriteLine("Area of
Rectangle is " + setDim());
}
public static void Main()
{
Area obj = new Area();
obj.getArea();
}
}
}
-----------------------------------------------------The End-------------------------------------------------------------
Comments
Post a Comment