manual c++-1
manual c++-1
December 2016/17
AKSUM UNIVERSITY
December 2016/17
AKSUM UNIVERSITY
#include<iostream> #include<iostream>
using namespace std; using namespace std;
int main() int main()
{
{
int a; int totalexp, qty, price,
discount;
cout<<"Enter any number : ";
cin>>a;
cout<<"Enter quantity:";
cin>>qty;
if(a%2==0)
cout<<"The number is cout<<"Enter price:";
cin>>price;
even";
else
cout<<"The number is totalexp=qty*price;
odd";
if(totalexp>5000)
{
return 0;
}
discount=(totalexp*0.1);
totalexp=totalexp-
Question Find the absolute value of a discount;
2 number entered by the user. }
#include<iostream>
using namespace std; cout<<"Total Expense is Rs.
int main() "<<totalexp;
{ return 0;
int a; }
cout<<"Enter any number:";
cin>>a; Question Write a program to determine
4 whether the seller has made
if(a>0) profit or incurred loss. Also
cout<<"The absolute determine how much profit he
value of number is:"<<a;
made or loss he incurred. Cost
else
cout<<"The absolute price and selling price of an
value of number is:"<<-(a); item is input by the user.
return 0;
}
December 2016/17
AKSUM UNIVERSITY
if (ram_age<sulabh_age
#include<iostream> && ram_age<ajay_age)
using namespace std; cout<<"Ram is
int main() youngest";
{ else
int cp,sp,result; if(sulabh_age<ram_age &&
sulabh_age<ajay_age)
cout<<"Enter cost price of cout<<"Sulabh
item : "; is youngest";
cin>>cp; else
cout<<"Enter selling price cout<<"Ajay is
of item : "; youngest";
cin>>sp; return 0;
}
result=sp-cp;
December 2016/17
AKSUM UNIVERSITY
DA=0.98*basic_salary;
}
gross_salary=basic_salary+HR
A+DA;
cout<<"Gross salary is :
"<<gross_salary;
return 0;
}
Question Write a program to calculate
9 the monthly telephone bills as
Questio In a company an employee is paid per the following rule:
n8 as under: If his basic salary is less Minimum Rs. 200 for upto 100
than Rs. 1500, then HRA = 10% of calls. Plus Rs. 0.60 per call for
basic salary and DA = 90% of basic next 50 calls. Plus Rs. 0.50 per
salary. call for next 50 calls. Plus Rs.
If his salary is either equal to or 0.40 per call for any call
above Rs. 1500, then HRA = Rs. 500 beyond 200 calls.
December 2016/17
AKSUM UNIVERSITY
December 2016/17
AKSUM UNIVERSITY
December 2016/17
AKSUM UNIVERSITY
cout<<"Sum :"<<sum;
return 0;
}
December 2016/17
AKSUM UNIVERSITY
December 2016/17
AKSUM UNIVERSITY
do
Question 8 Write a program to calculate {
HCF of Two given number. cout<<"Enter number
#include<iostream> ";
using namespace std; cin>>n;
rem=dividend%divisor; }while(choice=='y' ||
if(rem==0) choice=='Y');
hcf=divisor;
else
{ cout<<"Positive Number
:"<<sum_p<<"\nNegative Number
dividend=divisor; :"<<sum_n<<"\nZero Number
divisor=rem; :"<<sum_z;
} return 0;
} }
December 2016/17
AKSUM UNIVERSITY
if(n>max)
max=n; if(digit1*digit1*digit1 +
if(n<min) digit2*digit2*digit2 +
min=n; digit3*digit3*digit3 == i)
December 2016/17
AKSUM UNIVERSITY
int main()
{
int i,n;
float sum=0;
for(i=1;i<=n;i++)
sum += 1.0/i;
cout<<"Sum : "<<sum;
return 0;
}
int main()
{
int i,n,sign=-1;
float sum=0;
cout<<"Enter the value of n
";
cin>>n;
for(i=1;i<=n;i++)
{
December 2016/17
AKSUM UNIVERSITY
FLOW OF CONTROL
[SET – 3]
Question 1
i) ********** ii) * iii) *
********** ** **
********** *** ***
********** **** ****
***** *****
iv) * v) 1 vi) 1
*** 222 212
***** 33333 32123
******* 4444444 4321234
********* 555555555 543212345
Question 2 Write a program to compute sinx for given x. The user should supply x and a
positive integer n. We compute the sine of x using the series and the computation
should use all terms in the series up through the term involving xn
sin x = x - x3/3! + x5/5! - x7/7! + x9/9! ........
Question 3 Write a program to compute the cosine of x. The user should supply x and a
positive integer n. We compute the cosine of x using the series and the
computation should use all terms in the series up through the term involving xn
cos x = 1 - x2/2! + x4/4! - x6/6! .....
December 2016/17
AKSUM UNIVERSITY
December 2016/17
AKSUM UNIVERSITY
for(i=1;i<=n;i+=2)
{
fact=1;
for(j=1;j<=i;j++)
{
p=p*x;
fact=fact*j;
}
sign=-1*sign;
sum+=sign*p/fact;
}
cout<<"sin "<<x<<"="<<sum;
return 0;
}
3/
#include<iostream>
using namespace std;
int main()
{
int i,j,n,fact,sign=-1;
float x, p=1,sum=0;
cout<<"Enter the value of x
: ";
cin>>x;
December 2016/17
AKSUM UNIVERSITY
December 2016/17