Professional Documents
Culture Documents
Write A Program That Takes 3 Values From User. Two Values of Integer and One Value of Float Data Type. Print Each Result On One Line
Write A Program That Takes 3 Values From User. Two Values of Integer and One Value of Float Data Type. Print Each Result On One Line
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)
Write a program that takes 3 values from user. Two values of integer and one
value of float data type. Print each result on one line.
SOURCE CODE
#include<iostream>
using namespace std;
int main()
{
int x ,y;
float z;
cout<<"please enter first integer:"<<endl;
cin>>x;
cout<<"please write second integer:"<<endl;
cin>>y;
cout<<"plese enter float:"<<endl;
cin>>z;
cout<<"\n"<<x<<"\n"<<y<<"\n"<<z;
return 0;
}
SNAPSHOT
Write a program that gets 2 integers input from user and store them in variables.
Do the five basic Arithmetic Operations (+ , - , *, /, %) of the two numbers. Print
the results of operations as below
SOURCE CODE
#include<iostream>
using namespace std;
int main()
{
int a,b;
int add,sub,multi;
float divi,mod;
add=a + b;
cout<<a<< " + "<<b<<" = "<<add<<endl;
sub=a-b;
cout<<a<< " - "<<b<<" = "<<sub<<endl;
multi=a*b;
cout<<a<< " * "<<b<<" = "<<multi<<endl;
divi=(float)a/b;
cout<<a<< " / "<<b<<" = "<<divi<<endl;
mod=a%b;
cout<<a<< " % "<<b<<" = "<<mod<<endl;
return 0;
}
SNAPSHOT
Exercise 3 : Percentage
Write a program that prompt user to input course name, obtained marks and
total marks. Calculate the percentage using this formula marks percentage =
marks obtained / total * 100
and display the results as follows.
SOURCE CODE
#include<iostream>
using namespace std;
int main()
{
string cours;
float p,x,y;
cin>>y;
p=(x/y)*100;
cout<<"in "<<cours<<"you have secured %"<<p<<endl;
return 0;
}
SNAPSHOT
Write a program that finds the value of X by using given formula. Take value of a
and b from user.
X= (a + b)2 – 2ab
SOURCE CODE
#include<iostream>
using namespace std;
int main()
{
//declearing variables
int a,b,x;
x=((a+b)*2)-2*a*b;
cout<<"your answer is :"<<x<<endl;
return 0;
SNAPSHOT
Write a program that plays a word game with the user. The program should ask
the user to enter the following:
User’s name
Year of birth (eg. 1990)
Name of university
A favorite hobby
A pet’s name
SOURCE CODE
int main()
{
string name,uname,hobby,pname;
int a;
cin>>name;
cout<<"Enter year of birth :";
cin>>a;
cout<<"Name Of University :";
cin>>uname;
cout<<"A favourite hobby :";
cin>>hobby;
cout<<"A pet's name :";
cin>>pname;
cout<<endl;
return 0;
}
SNAPSHOT
Exercise 6
Write a program that inputs a five-digit integer, separates the integer into its
Individual digits and prints the digits vertically. For example, if the user types
32156, the program should print:
6
5
1
2
3
SOURCE CODE
SNAPSHOT
Exercise 7
Area of this right-angled triangle can also be calculated using the following formula: a
=½*x*y
Note that: h=
hypotenuse x=
adjacent
y= opposite
Write a C++ program that prompt user to enter value of X and Y. You have to calculate
the value of Hypotenuse (h) and Area(a).
SOURCE CODE
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x,y,a;
float h;
Department of computer science Semester BSCS-1A
CSL-113: Computer Programming Lab Lab 02: Variables and Data Types
CSL-113 : Computer Programming Lab
Semester : BS CS – 1A
Name : Muhammad Zain
Enroll no : (02-134182-037)
return 0;
}
SNAPSHOT