Programming fundamentals Final Exam Answers
!! ئەڤ بەرسڤە من یێت دروست کرین چیت بیت من خەلەتی هەبن !!
static int Fact(int n)
{
int i, F = 1;
for (i = 1; i <= n; i++)
F = F * i;
return F;
}
static int power(int a, int b)
{
int i, P = 1;
for (i = 1; i <= b; i++)
P *= a;
return P;
}
static void Main(string[] args)
{
int x, n, m;
double y = 0;
x = int.Parse(Console.ReadLine());
n= int.Parse(Console.ReadLine());
for (int i = 1; i <= n; i++)
y += power(x, (i + (i+1)) / Fact(i + (i+1));
Console.WriteLine("y = {0}", y);
Console.ReadLine();
}
__________________________________________________
Q2 -A
static int Find_Area(int a,int b)
{
int x, y, z;
x = int.Parse(Console.ReadLine());
y = int.Parse(Console.ReadLine());
z = int.Parse(Console.ReadLine());
if (x > y)
if (x > z)
if (y > z)
Console.WriteLine("{0} , {1} , {2}",x,y,z);
else
Console.WriteLine("{0} , {1} , {2}",x,z,y);
else
Console.WriteLine("{0} , {1} , {2}",z,x,y);
else
if (y > z)
if (z > x)
Console.WriteLine("{0} , {1} , {2}",y,z,x);
else
Console.WriteLine("{0} , {1} , {2}",y,x,z);
else
Console.WriteLine("{0} , {1} , {2}",z,y,x);
Console.ReadKey();
}
___________________________
Q2 -B
static int Find_Area(int a,int b)
{
return (a * b);
}
static void Main(string[] args)
{
char sr;
sr = char.Parse(Console.ReadLine());
int x, y;
if (sr=='S')
{
Console.Write("enter the length of one line of square : ");
x = int.Parse(Console.ReadLine());
Console.WriteLine(Find_Area(x, x).ToString());
}
else if (sr=='R')
{
Console.Write("enter the length of rectangle : ");
x = int.Parse(Console.ReadLine());
Console.Write("enter thr wedth of rectangle : ");
y = int.Parse(Console.ReadLine());
Console.WriteLine(Find_Area(x, y).ToString());
}
Console.ReadLine();
}
_______________________________________________
Q3 - A
struct Employee
{
public string Name;
public int age;
public int salary;
};
static void Main(string[] args)
{
Employee[] E = new Employee[3];
for (int i = 0; i < E.Length; i++)
{
E[i].Name = Console.ReadLine();
E[i].age = int.Parse(Console.ReadLine());
E[i].salary = int.Parse(Console.ReadLine());
}
string Low_N = E[0].Name, High_N = E[0].Name;
int Low_S = E[0].salary, High_S = E[0].salary;
for (int i = 0; i < E.Length; i++)
{
if (E[i].salary > High_S)
{
High_S = E[i].salary;
High_N = E[i].Name;
}
if (E[i].salary < Low_S)
{
Low_S = E[i].salary;
Low_N = E[i].Name;
}
}
Console.WriteLine("highest salary : {0}", High_N);
Console.WriteLine("Loest salary : {0}", Low_N);
Console.ReadLine();
}
________________________
Q3 - B
static void Main(string[] args)
{
string str, serch = "not Found";
str = Console.ReadLine();
for (int i = 0; i < str.Length; i++)
if (str[i] == 'B')
serch = "Found";
Console.WriteLine(serch);
Console.ReadLine();
}
________________________
Q4 - A -1
static int square(int x,int y)
{
if (x > y)
return (x * x);
else
return (y * y);
}
________________________
Q4 - A -2
!! هەر ٢ د درستن!!
float[] Temps = { 17.4f, 16.3f, 18.43f, 21.9f, 17.8f, 18.43f, 26.7f };
float[] temps = new float[7] { 17.4f, 16.3f, 18.43f, 21.9f, 17.8f, 18.43f, 26.7f };
________________________
Q4 - B -1
static void Main(string[] args)
{
int x, y, total;
x = 1;
total = 0;
while (x<=4)
{
y = x * x;
Console.WriteLine(y);
total += y;
++x;
}
Console.WriteLine("Total is {0}", total);
Console.ReadLine();
}
OutPut
1
4
9
16
Total is 30
________________________
Q4 - B -2
static void Main(string[] args)
{
char ch = 'e';
switch(ch)
{
case 'A':
case 'a':
case 'O':
case 'o':
case 'E':
case 'e':
case 'U':
case 'u':
case 'I':
case 'i':Console.WriteLine("Vowel Letter");break;
default:Console.WriteLine("not Vowel");break;
}
Console.ReadLine();
}
OutPut
Vowel Letter
________________________
Q5
static void Main(string[] args)
{
double[,] arr = new double[3, 3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
arr[i,j] = int.Parse(Console.ReadLine());
double sum = 0, Neg = 0, max = arr[0, 0], min = arr[0, 0];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
{
if (arr[i, j] >= 0)
sum += arr[i, j];
else
Neg++;
if (arr[i, j] > max)
max = arr[i, j];
if (arr[i, j] < min)
min = arr[i, j];
}
Console.WriteLine("the sum of positive number = {0}", sum);
Console.WriteLine("number of negativ number = {0}", Neg);
Console.WriteLine(" Max = {0} \n Min = {1}", max, min);
Console.ReadLine();
}
Programming fundamentals Final Exam Answers
Reviewed by Salar Pro
on
3:54 PM
Rating:
No comments: