C# File
C# File
02413704418
Program 1.Write a program to display "Hello World".
Solution 1.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
classProgram
{
staticvoid Main(string[] args)
{
Console.WriteLine("Hello world");
}
}
}
Solution 2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Fahrenheit_to_Celsius
{
classProgram
{
1
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
staticvoid Main(string[] args)
{
double celsius;
Console.Write("Enter Fahrenheit temperature : ");
double fahrenheit = Convert.ToDouble(Console.ReadLine());
celsius = (fahrenheit - 32) * 5 / 9;
Console.WriteLine("The converted Celsius temperature is" + celsius);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace temperature_conversion
{
classProgram
{
staticvoid Main(string[] args)
{
int celsius, faren;
Console.WriteLine("Enter the Temperature in Celsius(°C) : ");
celsius = int.Parse(Console.ReadLine());
faren = (celsius * 9) / 5 + 32;
Console.WriteLine("Temperature in Fahrenheit is(°F) : " + faren);
Console.ReadLine();
}
}
2
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Solution 3
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Circle
{
classProgram
{
staticvoid Main(string[] args)
{
double radius, area;
Console.WriteLine("Enter Radius: ");
radius = Convert.ToDouble(Console.ReadLine());
area = Math.PI * radius * radius;
Console.WriteLine("\nArea of circle: " + area);
Console.ReadKey();
}
}
}
3
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
(ii) Area of Triangle given its three sides
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Triangle
{
classProgram
{
staticvoid Main(string[] args)
{
double area_t, s1, s2, s3;
Console.WriteLine("\n----Sides of Triangle are:---- ");
s1 = double.Parse(Console.ReadLine());
s2 = double.Parse(Console.ReadLine());
s3 = double.Parse(Console.ReadLine());
double s = (s1 + s2 + s3) / 2.0;
area_t = Math.Sqrt(s * (s - s1) * (s - s2) * (s - s3));
Console.WriteLine("\nArea of Triangle is:" + area_t);
}
}
}
4
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program 4. Write a program to find the roots of a quadratic equation.
Solution 4
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace quadratic
{
classProgram
{
staticvoid Main(string[] args)
{
int a, b, c;
d = b * b - 4 * a * c;
if (d == 0)
{
Console.Write("Both roots are equal.\n");
x1 = -b / (2.0 * a);
x2 = x1;
Console.Write("First Root Root1= {0}\n", x1);
Console.Write("Second Root Root2= {0}\n", x2);
}
elseif (d > 0)
{
Console.Write("Both roots are real and diff-2\n");
5
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Console.Write("First Root Root1= {0}\n", x1);
Console.Write("Second Root root2= {0}\n", x2);
}
else
Console.Write("Root are imaginary;\nNo Solution. \n\n");
}
}
}
Solution5
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace largest
{
classProgram
{
staticvoid Main(string[] args)
{
int num1, num2, num3;
Console.Write("\n\n");
Console.Write("Find the largest of three numbers:\n");
Console.Write("------------------------------------");
Console.Write("\n\n");
6
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Console.Write("Input the 3rd number :");
num3 = Convert.ToInt32(Console.ReadLine());
Solution6
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Table
{
classProgram
7
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
{
staticvoid Main(string[] args)
{
int i, num;
//Reading number
Console.WriteLine("Enter number to print table: ");
num = Convert.ToInt32(Console.ReadLine());
Solution 7
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace factorial
{
classProgram
{
staticvoid Main(string[] args)
{
int i, number, fact;
8
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
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();
}
}
}
Solution 8
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
classProgram
{
staticvoid Main(string[] args)
{
int[] a = newint[100];
Console.WriteLine("Number of elements in the array ?");
string s = Console.ReadLine();
int x = Int32.Parse(s);
Console.WriteLine("-----------------------");
Console.WriteLine(" Enter array elements ");
Console.WriteLine("-----------------------");
for (int i = 0; i < x; i++)
{
9
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
string s1 = Console.ReadLine();
a[i] = Int32.Parse(s1);
}
Console.WriteLine("--------------------");
Console.WriteLine("Enter Search element");
Console.WriteLine("--------------------");
string s3 = Console.ReadLine();
int x2 = Int32.Parse(s3);
int low = 0;
int high = x - 1;
while (low <= high)
{
int mid = (low + high) / 2;
if (x2 < a[mid])
high = mid - 1;
elseif (x2 > a[mid])
low = mid + 1;
elseif (x2 == a[mid])
{
Console.WriteLine("-----------------");
Console.WriteLine("Search successful");
Console.WriteLine("-----------------");
Console.WriteLine("Element {0} found at location {1}\n", x2, mid + 1);
return;
}
}
Console.WriteLine("Search unsuccessful");
}
}
}
10
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program 9. Write a program to sort an array using bubble sort.
Solution 9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BubbleSort
{
classProgram
{
staticvoid Main(string[] args)
{
int[] a = { 3, 2, 5, 4, 1 };
int t;
Console.WriteLine("The Array is : ");
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine(a[i]);
}
for (int j = 0; j <= a.Length - 2; j++)
{
for (int i = 0; i <= a.Length - 2; i++)
{
if (a[i] > a[i + 1])
{
t = a[i + 1];
a[i + 1] = a[i];
a[i] = t;
}
}
}
Console.WriteLine("The Sorted Array :");
foreach (int aray in a)
Console.Write(aray + " ");
Console.ReadLine();
}
}
}
11
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
(i) Addition
(ii) Subtraction
(iii) Multiplication
(iv) Transpose
Solution10
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Matrixx
{
classProgram
{
publicstaticvoid addition()
{
int m, n, i, j;
Console.Write("Enter Number Of Rows And Columns Of Matrices A and B : \n");
m = Convert.ToInt16(Console.ReadLine());
n = Convert.ToInt16(Console.ReadLine());
int[,] A = newint[10, 10];
Console.Write("\nEnter The First Matrix : \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
A[i, j] = Convert.ToInt16(Console.ReadLine());
12
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
}
}
}
Console.WriteLine();
}
Console.WriteLine("\nMatrix B: ");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(B[i, j] + "\t");
}
Console.WriteLine();
}
int[,] C = newint[10, 10];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
C[i, j] = A[i, j] + B[i, j];
}
}
Console.Write("\nSum Matrix : \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
13
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Console.Write(C[i, j] + "\t");
}
Console.WriteLine();
}
}
publicstaticvoid subtraction()
{
int m, n, i, j;
Console.Write("Enter Number Of Rows And Columns Of Matrices A and B : \n");
m = Convert.ToInt16(Console.ReadLine());
n = Convert.ToInt16(Console.ReadLine());
int[,] A = newint[10, 10];
Console.Write("\nEnter The First Matrix : \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
A[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
}
Console.WriteLine();
}
Console.WriteLine("\nMatrix B : \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
14
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
{
Console.Write(B[i, j] + "\t");
}
Console.WriteLine();
}
int[,] C = newint[10, 10];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
C[i, j] = A[i, j] - B[i, j];
}
}
Console.Write("\nDifference Matrix : \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(C[i, j] + "\t");
}
Console.WriteLine();
}
}
publicstaticvoid multiplication()
{
int i, j, m, n;
Console.WriteLine("Enter the Number of Rows and Columns : ");
m = Convert.ToInt32(Console.ReadLine());
n = Convert.ToInt32(Console.ReadLine());
int[,] a = newint[m, n];
Console.WriteLine("Enter the First Matrix");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
a[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("First matrix is:");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(a[i, j] + "\t");
15
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
}
Console.WriteLine();
}
int[,] b = newint[m, n];
Console.WriteLine("Enter the Second Matrix");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
b[i, j] = int.Parse(Console.ReadLine());
}
}
Console.WriteLine("Second Matrix is :");
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
Console.Write(b[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("Matrix Multiplication is :");
int[,] c = newint[m, n];
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
c[i, j] = 0;
for (int k = 0; k < 2; k++)
{
c[i, j] += a[i, k] * b[k, j];
}
}
}
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(c[i, j] + "\t");
}
Console.WriteLine();
}
}
publicstaticvoid transpose()
{
int m, n, i, j;
16
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Console.Write("Enter the Order of the Matrix : \n");
m = Convert.ToInt16(Console.ReadLine());
n = Convert.ToInt16(Console.ReadLine());
int[,] A = newint[10, 10];
Console.Write("\nEnter The Matrix Elements : \n");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
A[i, j] = Convert.ToInt16(Console.ReadLine());
}
}
Console.Clear();
Console.WriteLine("\nMatrix A : ");
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
Console.Write(A[i, j] + "\t");
}
Console.WriteLine();
}
Console.WriteLine("Transpose Matrix : ");
}
Console.WriteLine();
}
}
staticvoid Main(string[] args)
{
int n;
Console.WriteLine("Choose any One Operation to Perform");
Console.WriteLine("1. Addition");
Console.WriteLine("2. Subtraction");
Console.WriteLine("3. Multiplication");
Console.WriteLine("4. Transpose");
Console.WriteLine("\n Enter Operation no : ");
n = Convert.ToInt16(Console.ReadLine());
switch (n)
17
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
{
case 1:
addition();
break;
case 2:
subtraction();
break;
case 3:
multiplication();
break;
case 4:
transpose();
break;
default:
Console.WriteLine("Invalid Selection...!!");
break;
}
Console.Read();
}
}
}
18
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
19
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program 11. Write a program to demonstrate the use of const and readonly.
20
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Solution11
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Const
{
classProgram
{
constint a = 10;
staticvoid Main(string[] args)
{
constint b = 20;
constint c = b + a;
Console.WriteLine(c);
Console.ReadLine();
}
}
}
Program 12. Write a program using user-defined function to return all factors of a number
and display them.
21
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Solution 12
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Factors
{
classProgram
{
staticvoid Main(string[] args)
{
int num, x;
Console.WriteLine("Enter the Number ");
num = int.Parse(Console.ReadLine());
Console.WriteLine("The Factors are : ");
for (x = 1; x <= num; x++)
{
if (num % x == 0)
{
Console.WriteLine(x);
}
}
Console.ReadLine();
}
}
}
22
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program 13. Write a program to perform following operations on array:-
(i) insert
(ii) delete
Solution 13
23
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program 14. Write a program using user defined functions that takes an n-digit number
and performs following operations
Solution 14
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
classProgram
{
staticvoid Main(string[] args)
{
int number, sum = 0;
Console.WriteLine("Enter a number:");
int input = int.Parse(Console.ReadLine());
number = input;
while (number != 0)
{
int m = number % 10;
number = number / 10;
sum = sum + m;
}
Console.WriteLine("Sum of digits of the number:" + sum);
Console.ReadLine();
number = input;
int reverse = 0;
while (number != 0)
{
reverse = reverse * 10;
reverse = reverse + number % 10;
number = number / 10;
}
Console.WriteLine("Reversed Number is:" + reverse);
Console.ReadLine();
24
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
}
}
}
Solution 15
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Object
{
classProgram
{
staticvoid Main(string[] args)
{
test obj = newtest();
test obj1 = newtest();
test obj2 = newtest();
test obj3 = newtest();
Console.WriteLine("Number of objects created:" + test.count);
}
}
classtest
{
publicstaticint count=0;
public test()
{
count = count + 1;
}
}
}
25
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program 16 .Write a program to display the marks in 3 subjects, total marks and
percentage of each student of a class of 20 students with displaying 5 records per screen.
Solution 16
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
classProgram
{
staticvoid Main(string[] args)
{
double rl, phy, che, ca, total;
double per;
string nm, div;
Console.Write("\n\n");
Console.Write("Calculate the total, percentage and division to take marks of three subjects:\n");
Console.Write("-------------------------------------------------------------------------------");
Console.Write("\n\n");
26
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Console.Write("Input the marks of Chemistry : ");
che = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the marks of Computer Application : ");
ca = Convert.ToInt32(Console.ReadLine());
Program 17 .Write program that randomly generates a number from a range 10-99 and
checks whether it is Armstrong or not.
27
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Solution 17
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp9
{
classProgram
{
staticvoid Main(string[] args)
{
int n, r, sum = 0, temp;
Console.Write("Enter the Number= ");
n = int.Parse(Console.ReadLine());
temp = n;
while (n > 0)
{
r = n % 10;
sum = sum + (r * r * r);
n = n / 10;
}
if (temp == sum)
Console.Write("Armstrong Number.");
else
Console.Write("Not Armstrong Number.");
Console.ReadLine();
}
}
}
28
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Use methods Standard and Mean to calculate standard deviation and mean of values.
Solution 18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp3
{
classProgram
{
staticvoid Main(string[] args)
{
int n;
float mean, median, std;
Console.Write("Enter number of data points:");
n = int.Parse(Console.ReadLine());
if (n < 3)
{
Console.WriteLine("The number of data points should be greater than 2.");
}
else
{
29
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
}
mean = (float)sum / n;
//calculate median
//If n is odd, median=dataset[n/2]
//If n is even, median=(dataset[n/2]+dataset[1+n/2])/2
//The index of array starts from 0, so you need to subtract 1 from the //indices used in
calculating the median
if (n % 2 != 0) median = dataset[n / 2];
else median = (dataset[(n / 2) - 1] + dataset[n / 2]) / (float)2;
int max;
int k = 0;
max = mode[0, 0];
for (j = 0; j < n; j++)
if (max < mode[j, 0]) { max = mode[j, 0]; k = j; }
30
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
{
temp = temp + (float)Math.Pow(dataset[j] - mean, 2);
}
//Show results
Console.WriteLine("Statistical Information:");
Console.WriteLine("..................................................");
Console.WriteLine("Arithmetic mean:{0}", mean);
Console.WriteLine("Median:{0}", median);
if (mode[k, 1] != 0)
Console.WriteLine("Mode:{0}", mode[k, 1]);
else Console.WriteLine("Mode: no mode");
Console.WriteLine("Standard deviation:{0}", std);
}
Console.ReadLine();
///bubble sort
31
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program 19. Write a program to demonstrate the working of any Ten String class
functions.
Solution 19
32
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program20.Write a program to sort a list of strings.
Solution 20
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace String
{
classProgram
{
staticvoid Main(string[] args)
{
string str;
char[] arr1;
char ch;
int i, j, l;
Console.Write("\n\nSort a string array in ascending order :\n");
Console.Write("--------------------------------------------\n");
Console.Write("Input the string : ");
str = Console.ReadLine();
l = str.Length;
arr1 = str.ToCharArray(0, l);
}
}
33
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Program21.Write a program that takes two arrays as input and produces a third array by
merging them.
Solution 21
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp11
{
classProgram
{
staticvoid Main(string[] args)
{
int[] array1 = newint[5];
int[] array2 = newint[5];
int[] array3 = newint[array1.Length + array2.Length];
Console.WriteLine("Enter Any 5 Elements for the First Array :");
for (int i = 0; i < 5; i++)
{
array1[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("Enter Any 5 Elements for the Second Array :");
for (int i = 0; i < 5; i++)
{
array2[i] = int.Parse(Console.ReadLine());
}
Buffer.BlockCopy(array1, 0, array3, 0, array1.Length * sizeof(int));
34
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Buffer.BlockCopy(array2, 0, array3, array1.Length * sizeof(int), array2.Length *
sizeof(int));
Console.WriteLine("Elements in the Third Array After Merging First and Second Arrays
:");
foreach (int value in array3)
{
Console.WriteLine(value);
}
Console.ReadLine();
}
}
}
Program22.Define a jagged array and write methods to input its elements and display.
Solution 22
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp7
{
classProgram
{
35
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
staticvoid Main(string[] args)
{
//Creations of jaggedArray
string[][] jaggedArray = newstring[3][];
jaggedArray[0][0] = "Hello";
jaggedArray[0][1] = "How are u";
jaggedArray[0][2] = "Rashpreet";
jaggedArray[1][0] = "Hello";
jaggedArray[2][0] = "Hello";
jaggedArray[2][1] = "How are u";
}
}
}
36
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Solution 23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
classProgram
{
staticvoid printarray(int[] arr)
{
Console.WriteLine("\nElements of array is:\n");
foreach (int i in arr)
{
Console.Write("\t{0}", i);
}
Console.WriteLine("\n");
}
staticvoid Main(string[] args)
{
//Initializing and storing value in arr1
int[] arr1 = newint[5] { 43, 25, 33, 14, 5 };
int[] arr2 = newint[5];
int len, rank;
bool fixedsize, read_only;
37
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
//Check array length
len = arr1.Length;
Console.WriteLine("Length:\t{0}", len);
//Sorting an array
Array.Sort(arr1);
printarray(arr1);
Console.ReadLine();
}
}
}
38
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Solution 24
using System;
using System.Collections;
namespace ConsoleApp5
{
classProgram
{
staticvoid Main(string[] args)
{
ArrayList al = new ArrayList();
Console.Write("Content: ");
foreach (int i in al)
39
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
{
Console.Write(i + " ");
}
Console.WriteLine();
Console.Write("Sorted Content: ");
al.Sort();
foreach (int i in al)
{
Console.Write(i + " ");
}
Console.WriteLine();
Console.ReadKey();
}
}
}
40
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp12
{
classProgram
{
staticvoid Main(string[] args)
{
string str;
int alp, digit, splch, i, l;
alp = digit = splch = i = 0;
while (i < l)
{
if ((str[i] >= 'a'&& str[i] <= 'z') || (str[i] >= 'A'&& str[i] <= 'Z'))
{
alp++;
}
elseif (str[i] >= '0'&& str[i] <= '9')
{
digit++;
}
else
{
splch++;
}
i++;
}
41
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
Console.Write("Number of Digits in the string is : {0}\n", digit);
Console.Write("Number of Special characters in the string is : {0}\n\n", splch);
Console.ReadLine();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp13
{
classProgram
{
staticvoid Main(string[] args)
{
int count = 0;
42
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
for (int j = 0; j < input.Length; j++)
if (input[0] == input[j])
count++;
Console.WriteLine(count);
Console.ReadLine();
}
}
}
43
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
c. Count the number of words
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp14
{
classProgram
{
staticvoid Main(string[] args)
{
string str;
int wrd, l;
l = 0;
wrd = 1;
l++;
}
}
}
}
44
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp14
{
classProgram
{
staticvoid Main(string[] args)
{
string s, revs = "";
Console.WriteLine(" Enter string");
s = Console.ReadLine();
for (int i = s.Length - 1; i >= 0; i--) //String Reverse
{
revs += s[i].ToString();
}
if (revs == s) // Checking whether string is palindrome or not
{
Console.WriteLine("String is Palindrome \n Entered String Was {0} and reverse string
is {1}", s, revs);
}
else
{
Console.WriteLine("String is not Palindrome \n Entered String Was {0} and reverse
string is {1}", s, revs);
}
Console.ReadKey();
}
}
}
45
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp14
{
classProgram
{
staticvoid Main(string[] args)
{
string Str, reversestring = "";
int Length;
Console.Write("Enter A String : ");
Str = Console.ReadLine();
Length = Str.Length - 1;
while (Length >= 0)
{
reversestring = reversestring + Str[Length];
Length--;
}
Console.WriteLine("Reverse String Is : {0}", reversestring);
Console.ReadLine();
}
}
}
46
C# PRACTICAL FILEMCA-3 RASHPREET KAUR
02413704418
47