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

Bahria University,

Karachi Campus

COURSE: CSC-113 COMPUTER PROGRAMMING


TERM: FALL 2019, CLASS: BSE- 1 (A)

Submitted By:

____Zain Rizvi________________________46064_______
(Name) (Reg. No.)
Submitted To:

Engr. Adnan ur rehman/ Engr. Ramsha Mashood


[Lab no.8] [Computer Programming]
[WHILE LOOP]
Signed Remarks: Score:

INDEX
SNO DATE LAB LAB OBJECTIVE SIGN
NO

1 3/oct/2020 1 Programming Basic

2 11/oct/2020 2 Variable and Arithmetic operation

3 18/oct/2020 3 input and output

4 27/oct/2020 4 Formatted output

5 28/Nov/2020 5 operations and Expressions

6 29/Nov/2020 6 conditional statement

7 8/Nov/2020 7 LOOP

8 13/Nov/2020 8 while and do-while Loops


[Lab no.8] [Computer Programming]
[WHILE LOOP]

SNO DATE LAB LAB OBJECTIVE SIGN


NO
[Lab no.8] [Computer Programming]
[WHILE LOOP]

Bahria University,
Karachi Campus

LAB EXPERIMENT NO.


____08___
LIST OF TASKS
TASK NO OBJECTIVE
1 Fibonacci series ( 0,1,1,2,3,5,8…) for and while loop
2 Repeatedly print the value of the variable xValue, decreasing it by 0.5 each time, as long as
xValue remains positive. (while loop)
3 Print the square roots of the first 25 odd positive integers. (while loop)
[Lab no.8] [Computer Programming]
[WHILE LOOP]
Submitted On:
13/ Nov /2020
(Date: DDMM/YY)
[Lab no.8] [Computer Programming]
[WHILE LOOP]

Task No. 1: Fibonacci series ( 0,1,1,2,3,5,8…) for and while loop

Solution:
class task1
{
public void t1() {
int prev = 0, current = 1, next = 0;
Console.Write(0 +" ");
while (current < 50)
{
Console.WriteLine(current + " ");
next = prev + current;
prev = current;
current = next;

}
Console.ReadKey();

}
}

Output:
[Lab no.8] [Computer Programming]
[WHILE LOOP]

Task No. 2: Repeatedly print the value of the variable xValue, decreasing it by 0.5 each
time, as long as xValue remains positive. (while loop)

Solution:
class task2
{public void t2() {

Console.Write("Enter number :");


double x = Convert.ToDouble(Console.ReadLine());
while (x >= 0)
{

Console.WriteLine(x);
x = x - 0.5;
}
Console.Read();
}
}
Output:
[Lab no.7] [Computer Programming]
[FOR LOOP]
Task No. 3: Print the square roots of the first 25 odd positive integers. (while loop)

Solution:
class task3
{
public void t3()
{
int n = 1;
Console.WriteLine("Number" + " square root");
while (n < 50)
{
Console.WriteLine(n+" "+ Math.Sqrt(n));
n = n + 2;
}
Console.ReadKey();
}
}

Output:

You might also like