0% found this document useful (0 votes)
17 views

Lab 03

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lab 03

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Sukkur IBA University Khairpur Campus

PROGRAMMING FUNDAMENTALS
Lab 03: Use of Variables, Datatypes and Operators

Course Programming Fundamentals


Course Code CSC-102
Course Instructor(s) Nadeem Ahmed Tunio
Date (Lab Conducted) 28th August 2024 Date (Lab Submitted)

Objectives of Lab No. 3:


1. Use cin >>
2. Variables
3. Datatypes
4. Operators

Practice Task No. 1:


Write a program which accepts two numbers and print their sum.

Solution:
#include<iostream>
using namespace std;
int main()
{
int a, b, c;
cout<< "\nEnter first number : ";
cin>>a;
cout<<"\nEnter second number : ";
cin>>b;
c=a+b;
cout<<"\nThe Sum is : " <<c;
return 0;
}
Practice Task No. 2:
Write a program which accept temperature in Farenheit and print it in centigrade.

Solution:
#include<iostream>
using namespace std;

int main()
{
float F, C;
cout<< "\nEnter temperature in Farenheit : ";
cin>>F;
C=5*(F-32)/9;
cout<<"Temperature in celcius is : "<<C;return 0;
}

Practice Task No. 3:


Write a program which accept principle, rate and time from user and print thesimple interest.

Solution:
#include<iostream>
using namespace std;
int main()
{
int p, r, t, i;
cout<<"Enter Principle : ";
cin>>p;
cout<<"Enter Rate : ";
cin>>r;
cout<<"Enter Time : ";
cin>>t;
i=(p*r*t)/100;
cout<<"Simple interest is : "<<i;
return 0;
}
Practice Task No. 4:
Write a program to swap the values of two variables.

Solution:
int main()
{
int a,b,temp;
cout<<"\nEnter two numbers : ";
cin>>a>>b;
temp=a;
a=b;
b=temp;
cout<<"\nAfter swapping numbers are : ";
cout<<a<<" "<<b;
return 0;
}

Practice Task No. 5:


Write a program to calculate area of circle.

Solution:
#include<iostream>
using namespace std;
int main()
{
float r,area;
cout<< "\nEnter radius of circle : ";
cin>>r;
area = 3.14*r*r;
cout<<"Area of circle : "<<area;
return 0;
}
Exercise
1: Write a program to swap value of two variables without using third variable.

2: Write a program which accepts days as integer and display total number ofyears, months and
days in it.

For example: If user input as 856 days the output should be 2 years 4 months 6days.

3. Write a program in C++ to compute quotient and remainder.

Sample Output:

4. Write a program in C++ to verify that the entered number is EVEN or ODD by using ternary operator.
Output should look like below:

5. Write a program to swap value of three variables without using fourth variable.
6. Write a program which accept temperature in centigrade and print it in Fahrenheit.
7. Write a program which accept temperature in kelvin and print it in centigrade.

You might also like