Lab Report 08 Abdullah Zafar 405642 ME-14 (C) 405642
Lab Report 08 Abdullah Zafar 405642 ME-14 (C) 405642
Lab Report 08
1st SEMESTER
Input Program:
#include<iostream>
int main()
int i,j;
cout<<"\n";
cout<<"*";
return 0;
Output:
Q.2 Write a Program using while loops to take in few numbers and produce the result on the
basis of meeting of condition criterion.
Input Program:
#include<iostream>
int main()
int a,b;
a=5;
b=9;
while(b>a)
cout<<b;
a=a+1;
return 0;
Output:
Otherway around of this program
#include<iostream>
int main()
cout<<"\n My name is ABdullah Zafar and I study in ME-14(C) with CMS ID=405642"<<endl;
while(b>a)
cout<<(b>a)<<endl;
a++;
Output:
Q.4 Write a program using while loop to print out multiplication table (Say of 5)
Input Program:
#include<iostream>
using namespace std;
int main()
{
int a, b;
cout << "\n My name is ABdullah Zafar and I study in ME-14 with CMS=405642"
<< endl;
a = 5;
b = 0;
}
return 0;
}
Output Program:
Q.5 Write a C++ Program to calculate the final velocity of a body from a given value of
acceleration and time.
Input Program:
#include<iostream>
int main()
cout<<"\n My name is Abdullah Zafar and I study in ME_14(C) with CMS ID=405642"<<endl;
time=0.0;
while(time<=20.0)
velocity=a*time+v;
cout<<time<<"\t\t"<<velocity<<endl;
++time;
}
return 0;
Output:
Input:
#include<iostream>
using namespace std;
int main()
{
int a;
for(a=20;a>=0;--a)
{
cout<<a<<endl;
}
return 0;
}
Output:
Q.7 Write a program in C++ using nested looping to take in basic requirements of a student and
related to submission of lab report.
Input:
#include<iostream>
int main()
char section;
char ch;
cout<<"\n My NAme is ABdullah Zafar and I study in mE_14(C) with CMS 405642"<<endl;
do
cin>>section;
cin>>name;
cin>>CMS_ID;
cin>>title;
cin>>ch;
while(ch=='y'||ch=='Y');
return 0;
}
Output:
Lab Assignment
Q.1 Write a program using while looping to calculate the exponent of a number.
Input:
#include<iostream>
using namespace std;
int main()
{
X: //For continual movement
int a;
int b;
int c = 0;
int ans = 1;
cout << "\n Please Enter the Number(Base) (Whose exponennt is to be
calculated=";
cin >> a;
cout << "\n Please enter the Exponenet of the number=";
cin >> b;
while (c < b)
{
ans = ans*a;
c++;
}
cout << "\n The answer is=" << ans;
goto X;
return 0;
}
OR
#include<iostream>
using namespace std;
int main()
{
X: //For continual movement
int a;
int b;
int c = 1;
int ans = 1;
cout << "\n Please Enter the Number(Base) (Whose exponennt is to be
calculated=";
cin >> a;
cout << "\n Please enter the Exponenet of the number=";
cin >> b;
while (c <= b)
{
ans = ans*a;
c++;
}
cout << "\n The answer is=" << ans;
goto X;
return 0;
}
Output:
Q.2 Write a program to display a series of Fibonacci Numbers (Say upto 100 order).
#include <iostream>
using namespace std;
int main() {
int n, t1 = 0, t2 = 1, nextTerm = 0;
cout << "\n My name is Abdullah Zafar and I study in ME-14 with CMS Id of
405642" << endl;
cout << "Enter the number of terms required for Fibonacci Series: ";
cin >> n;
cout << "The Fibonacci Series for given Number of terms shall be= " << endl;
if (i == 1)
{
cout << "," << t1;
continue;
}
if (i == 2)
{
cout << "," << t2;
continue;
}
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
Output:
Q. Using nested looping (preferable for loop with if statements) print out the series of first 100
prime numbers between 1 and 100.
Program Input:
#include<iostream>
using namespace std;
int main()
{
int i; //For the Series of Prime Numbers within a prescribed range
int j; //2 is the first prime number so it is the initial starting
poiunt for the loop
int n = 0;
cout << "\n The Prime numbers between the range of 1 and 100 are=";
for (i = 1; i <= 100; i++) //Progresses the loop from 1 to 100
{
for (j = 2; j < i; j++) //Progresses from 2 as it is the first prime
number
{
if (i % j == 0)
{
n++;
break;
}
}
if (n == 0 && i != 0)
}
cout << endl;
return 0;
}
Output:
Q. Write a program in C++ that takes in an input of even numbers from 1 to 12 and prints the
sum of them. (The range is between 1 and 12).
Input Program:
#include<iostream>
using namespace std;
int main()
{
cout << "\n My name is Abduullah Zafar and I study in ME-14 with CMS
ID=405642" << endl;
int i = 1;
int sum = 0;
Output:
Q. Write a program to calculate the factorial of a number/numbers
Input Program:
#include<iostream>
using namespace std;
int main()
{
cout << "\n My name is Abdullah Zafar and I study in ME-14(C) with CMS
ID=405642" << endl;
X: //In order for the program to run again and again
performing multiple calculations
int n, m;
double f; //Initialized f with double type as it can hold
exponents of 308
cout << "\n Please Enter the Number whose Factorial is to be calculated=";
cin >> n;
m = n;
f = 1; //Initializing the value for f with 1
do
{
f = f * n;
n--; //Making decrement in the value of n in order to
calculate factorial
} while (n >= 1);
{
cout << "\n The Factorial of Number=" << f << endl;
}
goto X;
return 0;
}
Output: