Lab 03
Lab 03
PROGRAMMING FUNDAMENTALS
Lab 03: Use of Variables, Datatypes and Operators
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;
}
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;
}
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.
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.