Anda di halaman 1dari 7

Q1:-

Write a program that generates the following table


1990 135
1991 7290
1992 11300
1993 16200
Use a single cout statement for all output

CODE:-
#include<iostream> //preprocessor directive
#include<iomanip> //for setw
#include<conio.h> // This is necessary for getch()
using namespace std; //"using" directive
void main() //function name main
{
Int saqlain=1990; //declaring variable
cout<< saqlain << setw(8) << 135
<<endl<<1991<<setw(8)<<7290<<endl<<1992<<setw(8)<<11300<<e
ndl<<1993<<setw(8)<<16200; //setw changes field width
of output
getch(); //This enables to see the program output
}

OUTPUT
PATH
Q2:-
Write a program that generates the following output
10
20
19
Use an integer constant for the 10, an arithmetic assignment operator to
generate te 20, and a decrement operator to generate the 19.

CODE:-
#include<iostream> //preprocessor directive
#include<conio.h> // This is necessary for getch()
using namespace std; //"using" directive
void main() //function name main
{
int saqlain; //declaring variable
saqlain=10; //giving value to variable
cout<<saqlain<<endl; //displaying value of variable
saqlain*=2; //using assignment operator to multiply with 2
cout<<saqlain<<endl; //displaying value of saqlain
saqlain--; //decrement operator
cout<<saqlain<<endl; //displaying value of saqlain
getch(); //This enables to see the program output
}

OUTPUT
PATH
Q3:-
CODE:-
#include<iostream> //preprocessor directive
#include<conio.h> // This is necessary for getch()
using namespace std; //"using" directive
int main() //function name main
{
float n1,n2,ans; //variables for entering and storing number
char oper,saqlain; //character for storing character and operator
do //condition
{
cout<<"\nEnter first number, operator , second number : ";
//displaying user for entering numbers and operator
cin>>n1>>oper>>n2; //entering number and operator
switch(oper) //switch statement
{
case '+' : ans=n1+n2; break; //if user enters + then add
case '-' : ans=n1-n2; break; //if user enters - then add
case '*' : ans=n1*n2; break; //if user enters * then add
case '/' : ans=n1/n2; break; //if user enters / then add
default : ans=0; //when neither of above is entered
then ans=0
}
cout<< "Answer="<<ans; //display result
cout<<"\nDo another (Enter'y' or 'n')?"; //display to ask user to enter
y or n to do another calculation
cin>>saqlain; //input y or n
}
while(saqlain != 'n' ); //when saqlain is not equal to n
return 0; //This tells main() to return the value 0
getch(); //This enables to see the program output
}

OUTPUT:-

PATH:-