LAB REPORT (PF)
LAB REPORT (PF)
Lab Manual
Submitted by:
Noor Fatima
BS-DS-24-
Submitted to:
Ms. Fiza Khalil
Programming Fundamentals
Program:
A program is a set of instructions given to a computer to perform a specific task. It’s like a
recipe that tells the computer what steps to follow to achieve a certain result, such as adding
numbers, displaying a webpage, or sending an email. Programs can be written in different
programming languages like Python, Java, or C++, and they help automate tasks or solve
problems using computers.
Assembly language:
Assembly language is a low-level programming language that provides a symbolic
representation of a computer's machine code. It acts as a bridge between high-level languages
and machine code, allowing programmers to write instructions in a more readable format than
binary.
Binary language:
Binary language, or machine code, is the most fundamental level of programming language that
computers understand. It consists solely of binary digits (0s and 1s), representing the electrical
states (on and off) of a computer's hardware.
Algorithms:
An algorithm is a step-by-step procedure or formula for solving a specific problem or
performing a task. It consists of a finite sequence of well-defined instructions that, when
followed, lead to a desired outcome. Algorithms can be expressed in various forms, including
natural language, pseudocode , flowcharts, and programming languages.
LAB#1
Program:
#include <iostream>
int main() {
cout<<"Hello World";
return 0;
}
LAB#2
Program:
Write a program that prints sum, subtraction and multiplication of two numbers
in C++.
#include <iostream>
int main() {
int a=3;
int b=4;
sum=a+b;
sub=a-b;
mul=a*b;
return 0;
}
LAB#3
Program:
Write a program which accepts two numbers and print their sum and average.
#include <iostream>
int main(){
int a,b,sum;
float avg;
cin>>a;
cin>>b;
sum=a+b;
avg=sum/2;
cout<<sum<<endl;
cout<<avg<<endl;
return 0;
}
Program:
#include <iostream>
int main(){
int a=5,b=7,temp;
cout<<"before swapping"<<endl;
cout<<a<<endl;
cout<<b<<endl;
temp =a;
a=b;
b=temp;
cout<<"after swapping"<<endl;
cout<<a<<endl;
cout<<b<<endl;
return 0;
Program:
#include <iostream>
int main(){
float radius,area;
area= 3.14*radius*radius;
cout<<area;
return 0;
Program:
#include <iostream>
int main(){
float centigrade;
float fahrenheit;
cin>>fahrenheit;
cout<<endl;
return 0;
Program:
Write a program which accepts a character and display its ASCII value.
#include <iostream>
int main(){
char a;
cin >> a;
return 0;
Program:
Write a program which accepts days as integers and display total number of years
,months and days in it.
#include <iostream>
int main(){
int days;
cout << years << " years " << months << " months " ;
return 0;
}
Program:
1.Write a program that reads and prints whether it is negative, zero or positive.
#include <iostream>
int main(){
int num;
cout<<"enter a num";
cin>>num;
if(num>0)
else if (num<0)
cout<<"zero";
return 0;
#include<iostream>
int main(){
int num;
cin>>num;
if(num%2)
cout<<"even";
else
cout<<"odd";
return 0;
3. Write a program to calculate the total expenses. Quantity and price per item and input by
the user and discount of 10% is offered if the expense is more then 5000.
#include<iostream>
int main(){
int q,p,t,d;
cout<<"enter quantity";
cin>>q;
cout<<"enter price";
cin>>p;
t=p*q;
cout<<t;
if(t>5000){
d=(t*0.1);
t=t-d;
cout<<"total expense"<<endl;
return 0;
int main(){
int sub1,sub2,sub3,sub4,sub5,sum;
float p;
cin>>sub1;
cin>>sub2;
cin>>sub3;
cin>>sub4;
cin>>sub5;
sum= sub1+sub2+sub3+sub4+sub5;
p= (float(sum)/500)*100;
cout<<sum<<"sum"<<endl;
cout<<"p"<<p<<endl;
if (p>=90){
cout<<"first division";
cout<<"second division";
cout<<"third division";
cout<<"fouth division";
}else {
cout<<"fail";
}
return 0;}
C++ program that reads the temperature value and the unit (C for Celsius or F for
Fahrenheit), and then prints whether water is in a solid, liquid, or gas state at the
given temperature.
In this program:
#include <iostream>
using namespace std;
int main() {
float temp;
char unit;
return 0;
Program, the employes's salary is input find gross salary . if his basic salary is less then 15000
then hrs=10%of basics salary and daily allaowance=90% of basic salary . if his salary is equal
or above15000 then hrs=rs 500and da=98% of basic salary
#include <iostream>
int main(){
float basicsalary,da,hra,grosssalary;
cin>>basicsalary;
if(basicsalary<15000){
hra=0.10*basicsalary;
da=0.90*basicsalary;
}else{
hra=500;
da=0.98*basicsalary;
grosssalary=basicsalary+hra+da;
cout<<"gross-salary="<<grosssalary;
return 0;}
Write a program that reads amount and Check if amount is less than 1000. If not, then
print "program ends because amount is larger than 1000" but if yes, then Print" amount is
smaller than 1000 so please go into thisif/else" and inside this if else, check the followings:
Is amount less than 500 too, then print "stay in this if and go to its nested if and again
check, is amount less than 300 too, then print "oh! Ok, it's a small amount entered else, go
into one more if inside else part and check if amount is not equal to 1000, then print ""oh!
Ok, it's silently larger amount entered".
#include <iostream>
int main()
int amount;
{
cout <<"Amount is smaller than 1000 so please go into this if/else"<< endl;
else
return 0;
}
Task #1
int main(){
int sum=0;
for(int i=1;i<=10;i++){
sum+=i;
cout<<"sum"<<sum<<endl;
return 0;
int main(){
int sum=0,i=1;
while(i<=10){
sum+=i;
i++;
cout<<"sum"<<sum<<endl;
return 0;
}
int main(){
int factorial=1,i=1,n;
cout<<"enter a number";
cin>>n;
while(i<=n){
factorial*=i;
i++;
cout<<"factorial"<<factorial<<endl;
return 0;
int main(){
int factorial=1,n;
cout<<"enter a number";
cin>>n;
for(int i=1;i<=n;i++){
factorial*=i;
cout<<"factorial"<<factorial<<endl;
return 0;
Q3 Write a program to find the value the value of one number raised
to power of another
int main(){
cin>>base>>exponent;
while(exponent!=0){
result*=base;
--exponent;
cout<<result;
return 0;
}
Initially: result = 1
Iteration 1: result = 1 * 2 = 2, exponent = 2
Iteration 2: result = 2 * 2 = 4, exponent = 1
Iteration 3: result = 4 * 2 = 8, exponent = 0
Q4 Reverse of number:
int main(){
cout<<"enter a number";
cin>>n;
for(int i=0;i<=n;i++){
remainder =n% 10;
reversed=reversed*10+remainder;
n/=10;
return 0;
int main(){
cin>>n;
cin>>number;
if(number%2==0){
evennumber++;
}else{
oddnumber++;
}
cout<<"even number"<<evennumber<<endl;
cout<<"odd number"<<oddnumber<<endl;
return 0;
#include <iostream>
int main(){
int n,positive=0,negative=0,number;
cout<<"enter a number";
cin>>n;
cout<<"enter a number";
for(int i=0;i<n;i++){
cin>>number;
if(number >0){
positive++;
}else if
(number<0){
negative++;
}else{
cout<<"zero"<<endl;
cout<<positive<<"positive"<<endl;
cout<<negative<<"negative"<<endl;
return 0;
}
Write a programe to find armbstong of 1st three digits
int main() {
originalNumber = number;
while (originalNumber != 0) {
if (result == number)
else
cout << number << " is not an Armstrong number." << endl;
return 0;
#include<cmath>
using namespace std;
int main() {
int start=1,end=500;
for(int number=start;number<=end;number++){
int remainder,orignalnumber=number,result=0;
while (orignalnumber!=0){
remainder=orignalnumber%10;
result+=pow(remainder,3);
orignalnumber/=10;
if(result== number){
cout<<number<<endl;
cout<<endl;
return 0;
}
Task #2
int main(){
int n,number,smallest;
cin>>smallest;
for(int i=1;i<n;i++){
cin>>number;
if(number<smallest){
smallest=number;
return 0;
}
int main(){
for(int i=0;i<n;i++){
cin>>number;
sum+=number;
cout<<"sum of numbers"<<sum<<endl;
return 0;
}
Q 10 write a program that calculates and prints the average of several
integers. The integers are terminated by the sentinel value 9999, which
should not be included in the calculation.
int main(){
float average;
cout<<"enter integers"<<endl;
while(true){
cin>>number;
if(number==999){
break;
sum+=number;
count++;}
average=sum/count;
cout << "The average of the entered numbers is: " << average << endl;
return 0;
}
Q 11 To meet the requirements of printing all numbers from 0 to 6
except 3 and 6 using a continue statement, here’s the program:
#include<iostream>
int main(){
int n;
cout<<"enter integer";
cin>>n;
for(int i=0;i<n;i++){
if(i==3||i==6)
{continue; }
cout<<i<<"";
cout<<endl;
return 0;
}
Task#3
#include<iostream>
int main(){
int number;
cout<<"enter integer"<<endl;
for(int i =0;i<5;i++){
cin>>number;
if(number<1 || number>30){
continue;
for(int j=0;j<number;j++){
cout<<"*";
cout<<endl;
return 0;
int main(){
int n;
cin>>n;
for(int i=1;i<=10;i++){
cout<<n<<"x"<<i<<"="<<i*n<<endl;
return 0;
int n;
cin>>n;
for(int i=10;i>=1;i--){
cout<<n<<"x"<<i<<"="<<i*n<<endl;
return 0;
}
Program:1
Output:
Program:2
Output:
Program:3
Output:
Program:6
Output:
Program # 7
Program:8
Output:
Program:9
Output:
Program:10
Output:
Program # 11
Program:13
Output:
Program # 14
Output:
Program:
Output:
programe
Output: