BSE1A Zain Rizvi CPOEL1

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

BAHRIA UNIVERSITY, (Karachi Campus)

Department of Software Engineering


Open Ended Lab -1
Semester Fall 2020

Course Title: Computer Programming Course Code:


Course Instructor: Engr. Adnan ur Rehman Class: BSE-1(A)
Lab Instructor: Engr. Ramsha Mashood Name: Zain Rizvi
Max. Marks: 30 Marks Reg no: 46064
Time: 3 hours Date: 19-11-2020

NOTE:

 Plagiarism is not allowed, if found you will get zero marks.


 Try to submit the task on LMS in given Time.
 Include your name or enrollment no on footer.
 Your File name should be in the given format:
o [Class Section] [Complete Name] CPOEL1

i.e., BSE1A Usman Ali CPOEL1


TASK # 01: Create a simple C# Application to implement any real world problem using nested
loop (Marks: 10)

Solution:

int i, j;
int[,] arr1 = new int[3, 3];

Console.WriteLine("Enter 2 3x3 matrix values, to get output ");

Console.Write("------------------------------------------------------\n");

//Input Matrix
Console.Write("Input elements in the matrix :\n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
Console.Write("element - [{0},{1}] : ", i, j);
arr1[i, j] = Convert.ToInt32(Console.ReadLine());
}
}
//Out Put Matrix
Console.Write("\nThe matrix is : \n");
for (i = 0; i < 3; i++)
{

Zain Rizvi (02-134162-140)


Console.Write("\n");
for (j = 0; j < 3; j++)
Console.Write(" " + arr1[i, j]);
}
Console.ReadKey();
//Zain Rizvi 02-134162-140
}
}
}

Zain Rizvi (02-134162-140)


TASK # 02: Create a simple c# application to reverse any number given by user. Use any c#
method to implement that task. (Marks: 10)

Solution:
using System;
namespace Mids
{
class Program
{

static void Main(string[] args)


{
int num, reverse = 0;
Console.WriteLine("Enter a Number : ");
num = int.Parse(Console.ReadLine());
while (num != 0)
{
reverse = reverse * 10;
reverse = reverse + num % 10;
num = num / 10;
}
Console.WriteLine("Reverse Number is : " + reverse);
Console.ReadLine();

Zain Rizvi (02-134162-140)


//Zain Rizvi 02-134162-140
}
}
}

TASK # 03: The distance between two cities (in km) as input from user. Write a Program to
print the distance in any of the following unit according to user requirements: (Marks: 10)
 1 kilometer = 1000 meters
 1 kilometer = 3280.8399 feet
 1 kilometer = 39370.0787 inch
 1 kilometer = 100000 cm

Solution:
using System;
using System.Collections.Generic;
using System.Text;
namespace Mids
{
class Task_03
{
public void task3() {
Console.Write("Enter The Distance (In KM):");
double dist = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Press 1 for km to meter ");
Console.WriteLine("Press 2 for km to feet ");
Console.WriteLine("Press 3 for km to inch ");
Console.WriteLine("Press 4 for 1 km to 100000 cm ");
Console.WriteLine("__________________________");
int opt = Convert.ToInt32(Console.ReadLine());
double result = 0;
if (opt == 1)
{
Console.WriteLine("The Calculated distance in meter is " + dist *
1000);
}
else if (opt == 2)
{
Console.WriteLine("The Calculated distance in feet " + dist *
3280.8399);
}

Zain Rizvi (02-134162-140)


else if (opt == 3)
{
Console.WriteLine("The Calculated distance in inch" + dist *
39370.0787);
}
else if (opt == 4)
{
Console.WriteLine("The Calculated Distance " + dist * 100000);
}
else
{
Console.WriteLine("Wrong Option");
}
Console.ReadKey();

//Zain Rizvi 02-134162-140

}
}
}

Zain Rizvi (02-134162-140)

You might also like