Sie sind auf Seite 1von 18

Q1. Write a program to compute the area of a triangle.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
string A, B, C;
int An, Bn, Cn, x, y, z, m, t, s;
double area;
Console.WriteLine(" Enter the Sides of the triangle...");
Console.Write(" Length of Side A: ");
A = Console.ReadLine();
An = Int32.Parse(A);
Console.Write(" Length of Side B: ");
B = Console.ReadLine();
Bn = Int32.Parse(B);
Console.Write(" Length of Side C: ");
C = Console.ReadLine();
Cn = Int32.Parse(C);
s = (An + Bn + Cn)/2;
x = s - An;
y = s - Bn;
z = s - Cn;
m = x * y * z;
t = s * mul;
area = Math.Sqrt(t);
Console.Write(" Area of triangle ABC: " + area);
Console.ReadLine();

}
}
}
Q1. Write a program to compute the area of a triangle.

(Output)
Enter the sides of the triangle…
Length of Side A: 6
Length of Side B: 8
Length of Side C: 10
Area of triangle ABC: 12.32014268810711
Press any key to continue . . .
Q2. Write a program to generate the following sequence of numbers using For loop
construct and obtain them in the given format.
1
2 3
4 5 6
7 8 9 10
11 13 14 15

using System.Collections.Generic;
using System.Text;

namespace form
{
class Program
{
static void Main(string[] args)
{
int flag = 0;
for (int m = 0; m <= 5; m++)
{
Console.WriteLine();
for (int n = 1; n <= m; n++)
{
flag = flag + 1;
Console.Write(flag + " ");
}
}
Console.ReadLine();

}
}
}
Q2. Write a program to generate the following sequence of numbers using For loop
construct and obtain them in the given format.
1
2 3
4 5 6
7 8 9 10
11 13 14 15

(Output)
1
2 3
4 5 6
7 8 9 10
11 13 14 15
Q3. Write a program to obtain the following sequence of numbers.
1 -3 6 -10 15 -21 28 -36 45

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
int m = 1, n = 2;
Console.Write(i);
for (n = 2; n <= 9; n++)
{
if (n % 2 == 0)
{
m = m - n*n;
Console.Write(" "+m);
}
else
{
m = m + n*n;
Console.Write(" "+m);
}
}
}
}
}
Q3. Write a program to obtain the following sequence of numbers.
1 -3 6 -10 15 -21 28 -36 45

(Output)
1 -3 6 -10 15 -21 28 -36 45
Press any key to continue . . .
Q4. Write a program to find the largest element in the matrix.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{
int[,] a = new int[10, 10];
int s, m, k, i, j;
Console.Write("Enter the no. of Rows: ");
s = int.Parse(Console.ReadLine());
Console.Write("Enter the no. of Colums: ");
m = int.Parse(Console.ReadLine());
Console.WriteLine("\nEnter The Matrix:");
for (i = 0; i < s; i++)
{
for (j = 0; j < m; j++)
{

a[i,j] = Int32.Parse(Console.ReadLine());
}
}
k = a[0,0];
for (i = 0; i < s; i++)
{

for (j = 0; j < m; j++)


{

if (k < a[i,j])
{
k = a[i,j];
}

}
}
Console.WriteLine("The largest value in the Matrix is: " +k);
}
}
}
Q4. Write a program to find the largest element in the matrix.

(Output)
Enter the no. of Rows: 2
Enter the no. of Columns: 3

Enter The Matrix:


25
36
12
68
26
87
The largest value in the Matrix is: 87
Press any key to continue . . .
Q5. Write a program to read an array and print its elements in the reverse order.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication12
{
class Program
{
static void Main(string[] args)
{
int i;
string v1;
int n,v2;
int[] a = new int[25];
Console.Write("Enter size of the array: ");
n = Int32.Parse(Console.ReadLine());
for (i = 0; i < n; i++)
{
V1=Console.ReadLine();
V2 = Int32.Parse(vals);
a[i] = v2;
}
Console.Write(“The System is reversing the array pls wait...”);
for (i = n-1; i >= 0; i--)
{
Console.WriteLine(a[i]);
}

}
}
}
Q5. Program to read an array and print its elements in the reverse order.

(Output)
Enter size of the array: 5
23
78
56
12
90
The System is reversing the array pls wait...
90
12
56
78
23
Press any key to continue . . .
Q6. Write a program to display the abbreviation of a text.

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Console.Write("Pls enter a string of your choice: ");
string s = Console.ReadLine();
Console.Write(s[0]);
for(int i=0;i<s.Length;i++)
{
if(s[i]==' ')
{
Console.Write(" "+s[i+1]);
}

}
}
}
}
Q6. Write a program to display the abbreviation of a text.

(Output)
Pls enter a string of your choice: I am Nishant Kumaria
IaNK
Press any key to continue . . .
Q8. Write a program to count the number of vowels in a string using Switch-Case
control structure.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int flag = 0;
char c='0';
Console.WriteLine("Enter the String of ur choice: ");
String s = Console.ReadLine();
for (int i = 0; i < s.Length; i++)
{
c = s[i];
switch (ch)
{
case 'a':
case 'A': flag = flag + 1;
break;
case 'e':
case 'E': flag = flag + 1;
break;
case 'i':
case 'I': flag = flag + 1;
break;
case 'o':
case 'O': flag = flag + 1;
break;
case 'u':
case 'U': flag = flag + 1;
break;
}
}
Console.WriteLine("The no of vowels are: " + flag);

}
}
}
Q8. Write a program to count the number of vowels in a string using Switch-Case
control structure.

(Output)
Enter the String of ur choice:
I am Nishant Kumaria
The no of vowels are: 8
Press any key to continue . . .
Q9. Write a program to define a class to represent a Bank Account comprising the
following specifications

MEMBER FIELDS
* Name of the Depositor.
* Balance in the Account
* Account no.
* Type of acc.
MEMBER FUNCTIONS
* To assign initial values
* Deposition amount
* To withdraw after checking
* To display name & balance. */

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication16
{
class Program
{
static void Main(string[] args)
{
int n1, n2, n3, c, av, av1, cp;
int ac =1;
String name, s, d;
Console.Write(" Enter the account number: ");
n1 = Int32.Parse(Console.ReadLine());
Console.Write(" Enter the Name: ");
name = Console.ReadLine();
Console.Write(" Enter the Account type: ");
n2=Int32.Parse(Console.ReadLine());
Console.Write(" Enter the Starting Balance: ");
n3 = Int32.Parse(Console.ReadLine());
while (ac == 1)
{
Console.WriteLine(" Menu ");
Console.WriteLine(“*----*”);
Console.WriteLine(" 1.Deposit.");
Console.WriteLine(" 2.Withdraw.");
Console.WriteLine(" 3.Balance.");
Console.Write(" Enter your choice : ");
c = Int32.Parse(Console.ReadLine());
switch (c)
{
case 1:
Console.Write(" Enter the amount to be deposited : ");
av = Int32.Parse(Console.ReadLine());
Console.WriteLine(" Do you want to continue? <y/n>");
s = Console.ReadLine();
d = "y";
cp = string.Compare(s, d);

if (cp == 0)
{
Console.WriteLine(" Your account number : " + n1);
Console.WriteLine(" Name : " + name);
Console.WriteLine(" Account type : " + n2);
Console.Write("Balance : ");
n3 = av + nu3;
Console.Write(n3);
}

if (cp == 1)
{
break;
}
break;
case 2:
Console.Write(" Enter the amount to be withdrawn : ");
av1 = Int32.Parse(Console.ReadLine());
n3 = n3 - av1;
Console.WriteLine(" Do you want to continue? <y/n>");
s = Console.ReadLine();
d = "y";
cp = string.Compare(s, d);

if (cp == 0)
{
Console.WriteLine("Your account details : ");
Console.WriteLine(" Your account number : " + n1);
Console.WriteLine(" Name : " + name);
Console.WriteLine(" Account type : " + n2);
Console.WriteLine("Balance : ");
Console.Write(n3);
}
break;
case 3:
Console.WriteLine("current Balance : ");
Console.WriteLine(n3);
break;

}
}
}

}
Q9. Write a program to define a class to represent a Bank Account comprising the
following specifications

MEMBER FIELDS
* Name of the Depositor.
* Balance in the Account
* Account no.
* Type of acc.
MEMBER FUNCTIONS
* To assign initial values
* Deposition amount
* To withdraw after checking
* To display name & balance. */

(Output)
Enter the account number: 30091
Enter the Name: Ayna
Enter the Account type: savings
Enter the Starting Balance: 19990

Menu
*----*
1.Deposit.
2.Withdraw.
3.Balance.
Enter your choice : 1

Enter the amount to be deposited : 1000


Do you want to continue? <y/n>
y

Your account number : 30091


Name : Ayna
Account type : savings
Balance : 20990

Menu
*----*
1.Deposit.
2.Withdraw.
3.Balance.
Enter your choice : 2

Enter the amount to be withdrawn : 1000


Do you want to continue? <y/n>
y

Your account number : 30091


Name : Ayna
Account type : savings
Balance : 19990

Menu
*----*
1.Deposit.
2.Withdraw.
3.Balance.
Enter your choice : 3
current Balance : 19990

Menu
*----*
1.Deposit.
2.Withdraw.
3.Balance.
Enter your choice :

Das könnte Ihnen auch gefallen