Professional Documents
Culture Documents
Karachi Campus
Submitted By:
_____Zain Rizvi________________________46064________
(Name) (Reg. No.)
Submitted To:
INDEX
SNO DATE LAB LAB OBJECTIVE SIGN
NO
Submitted On:
__3/10/2020__
(Date: DD/MM/YY)
[Lab no.1] [Computer Programming]
[Programming Basic]
1. Go to this link
https://www.visualstudio.com/downloads/
2. Download the visual studio exe file.
3. After the download finishes , you can click on the downloaded file to install. Visual
studio download some files.
4. In next screen,
Task No. 2: Show the output of all examples mention in the lab.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lab_01_Examples
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}
Output:
Task No. 3.1: Debug the following program and write the values of n, sum and m while debugging
Solution:
using System;
public class SumExample
{
public static void Main(string[] args)
{
int n,sum=0,m;
Console.Write("Enter a number: ");
n= int.Parse(Console.ReadLine());
while(n>0)
[Lab no.1] [Computer Programming]
[Programming Basic]
m=n%10;
sum=sum+m;
n=n/10;
}
Console.Write("Sum is= "+sum);
}
}
Output:
Task No. 3.2: Debug the following program and write the values of n, sum and m while debugging
Solution:
using System;
int age;
string name;
Console.WriteLine("Enter your name");
name = Console.ReadLine();
Console.WriteLine("Enter your age");
age = Convert.ToInt32(Console.ReadLine());
if (age >= 18)
{
Console.WriteLine("Hello " + name + "!" + "You can vote");
[Lab no.1] [Computer Programming]
[Programming Basic]
}
else {
Console.WriteLine("Hello " + name + "!" + " Sorry you can't vote");
}
Console.Read();
}
}
Output:
Bahria University,
Karachi Campus
Submitted On:
11/10/2020
(Date: DD/MM/YY)
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]
Task No. 1: Write a program to display your personal information. (Name, age, address,
father’s name, college name, NIC, phone number etc. ) and display your marks sheet.
((Use Escape Sequences to create a formatted Output according to the given image).
Solution:
public void t1() {
String name, lname, Fname, email, edu;
int age, Phone;
Output:
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]
Task No. 3:Write a C# program that displays the results of the expressions:
3.0*5.0
7.1*8.3-2.2
3.2/ (6.1*5)
15/4
15%4
5*3-(6*4).
Solution:
Output:
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]
Output:
}}
[Lab no.2] [Computer Programming]
[Variable and Arithmetic
operation]
Output:
Task No. 6: Display the result of the expression: ((( a + b) * (c * e * d)) – e)/f
Solution:
class Task6
{
public void t6()
{
double a, b, c, d, e, f;
Console.Write("Enter Value of a:");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of b:");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of c:");
c = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of d:");
d = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of e:");
e = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Value of f:");
f = Convert.ToDouble(Console.ReadLine());
double x = a + b, y = c * d * e;
double mul = x * y;
double sub = mul - e;
Submitted On:
18/ oct /2020
(Date: DD/MM/YY)
[Lab no.3] [Computer Programming]
[input and output]
[Lab no.3] [Computer Programming]
[input and output]
[Lab no.3] [Computer Programming]
[input and output]
Task No. 1: Write a program which take two integer values from user and perform mathematical
operations(Addition, Subtraction, Multiplication and Division) on these two values.
Solution:
class Task1
{
public void t1() {
int num1, num2;
Console.WriteLine("**********TASK 1**********");
Console.WriteLine("Enter First number: ");
num1 =Convert.ToInt16( Console.ReadLine());
Console.WriteLine("Enter Second number: ");
num2 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("**************************");
int add, sub, mul;
double div;
add = num1 + num2;
sub = num1 - num2;
mul = num2 * num1;
div = Convert.ToDouble(num1) / Convert.ToDouble(num2);
Console.WriteLine("**************************");
Console.WriteLine("Add = " + add);
Console.WriteLine("Subtract= "+sub);
Console.WriteLine("Multiply=" + mul);
Console.WriteLine("Divide=" + div);
Console.WriteLine("**************************");
}
Output:
[Lab no.3] [Computer Programming]
[input and output]
Task No. 2: Write a program to take personal information from user and display it.
Output:
[Lab no.3] [Computer Programming]
[input and output]
[Lab no.3] [Computer Programming]
[input and output]
Task No. 3: Calculate the quadratic equation by using three user given integer variables.
Solution:
public void t3() {
int a1, b1, c1;
Console.WriteLine("===============Task 3===============");
Console.WriteLine("Program To Calculate Quadratic Equation\n\n\n");
Console.WriteLine("Enter first num: ");
a1 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter second num: ");
b1 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("Enter third num: ");
c1 = Convert.ToInt16(Console.ReadLine());
double sol2;
sol2 = Math.Sqrt((b * b) - 4 * (a) * (c));
sol2 = -b - sol2;
sol2 = sol2 / (2 * a);
Console.WriteLine("x=( " + sol2 +" , "+sol1+")");
Console.ReadKey();
Solution:
public void t4() {
Console.WriteLine("=========Task 4=========");
double a, b, c, d, f,e;
Console.Write("Enter a Value:");
a = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter b Value:");
b = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter c Value:");
c = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter d Value:");
d = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter e Value:");
e = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter f Value:");
f = Convert.ToDouble(Console.ReadLine());
double result1,result2;
result1 = b + 3;
result2 = 4 * a * c;
result1 = Math.Pow(result1, result2);
result1 = result1 / d;
double result3,result4;
result3 = a * c;
result4 = b * d;
result3 = result3 + result4;
result3 = result3 * f;
result1 = result1 + result3;
Console.Write("Calculated result is :" + result1);
}
}
}
Output:
[Lab no.3] [Computer Programming]
[input and output]
Task No. 5: Write a program and print the output of first equation of the motion. For
values take input from user. (vf=vi+at)
Solution:
class Task_5
{
public void t5() {
}
}
}
Output: