Professional Documents
Culture Documents
. Do these
calculations in output statements.
Answer
-inc$u#e<iostream.h>
/oi# main0)
1
onst &$oat :i23.1415;;
int r;
cout<<"enter ra#ius 2 ";
cin>>r;
cout<<"%n#iameter 2 "<<' 3 r <<en#$;
cout<<" circum&erence 2"<<' 3 "i 3 r <<en#$;
cout<<"area 2"<< "i 3 r 3 r <<en#$;
7
<)
9hat is output of the follo'in proram=8
- inc$u#e<iostream.h>
/oi# main0)
1
int i,=;
&or0i21;i<26;i!!)
1
&or0=2>;=<2i;=!!)
cout<<"3";
cout<<en#$;
7
7
Ans
/
/ /
/ / /
/ / / /
/ / / / /
/ / / / / /
1>)
9rite the %&& proram to find the sum and averae of a
set of n inteer numbers.
Answer
-inc$u#e<iostream.h>
/oi# main0)
1
int n, i, 8 sum2>, a/erage;
cout<<"enter n 2 ";
cin>>n;
&or0i2>;i<2n;i!!)
1
cout<<"enter 82 ";
cin>>8;
sum !2 8;
7
a/erage 2 sum5n;
cout<<"sum 2 "<<sum<<en#$;
cout<<"a/erage 2"<<a/erage<<en#$;
;)
9rite the %&& proram to find the sum of odd inteers
bet'een + and 77 usin a for structure.
Answer
-inc$u#e<iostream.h>
/oi# main0)
1
int sum2>;
&or0i2>;i<2;;;i2i!')
sum !2i;
cout<<" sum o& o## integers between 1 an# ;; 2"<<sum;
7
11)
9rite the %&& proram to find the factorial of any inteer
number n.
Answer
-inc$u#e<iostream.h>
/oi# main0)
1
int i, n, &act21;
cout<<"enter n 2 ";
cin>>n;
&or0i21;i<2n;i!!)
&act 32i;
cout<<"the &act o& "<<n<<" 2"<<&act;
7
1')
9rite the %&& proram to find the square and square root
of +> inteer numbers+8+> usin 'hile loop.
Answer
-inc$u#e<iostream.h>
-inc$u#e<math.h>
-inc$u#e<iomani".h>
/oi# main0)
1
int i;
cout<<" i i3i
sqrt0i)"<<en#$;
cout<<"444444444444444444444444444444444444444444444444444
44444"<<en#$;
i21;
whi$e0i<21>)
1
out<<setw04)<<i<<setw04)<<i3i<<setw04)<<sq
rt0i)<<en#$;
i!21;
7
7
13)
9hat does this proram print
-inc$u#e<iostream.h>
/oi# main0)
1
int 9, 821, tota$2>;
whi$e08<21>)
1
9 2 8 3 8;
cout<<9<<en#$;
tota$ !2 9;
!!8;
7
out<<"tota$ is "<<tota$<<en#$;
7
Answer
- - - -
+> 3 - + + + + +
14)
*ind the errors in each of the follo'in code sements
and e)plain ho' to correct them 6ans'er only eiht)
0a)
cout >>The result=<<area;
?o ,rror orrection
+ @@ AA
- #is not found #
0b)
if (d=1)
cout <<Sat"<<endl;
else;
cout <<"not Sat"<<endl;
0c)
for (int i=1;i<=100;i+)
Cout<<i<<andl;
0#)
#include <iostream>
oid maim ()
?o ,rror orrection
+ 4 44
- Blse( Blse
?o ,rror orrection
+ :& :&&
- .ndl Bndl
?o ,rror orrection
+ Aiostream@ Aiostream.h@
- Caim main
0e)
oid main();
!
cout<<""elcome to #a$or e%am
&"<<end;
'
0&)
int a?3@201',6,;);
&or0int i2>; i<3; i!!)
cout <<a;
0i)
#oub$e 8?4@2 11.1 , '.3 , 4.4 , 5.< ,6.;7;
cout <<a?1@<<" "<<a03);
?o ,rror orrection
+ Doid main6)( Doid main6)
- Bnd Bndl
?o ,rror orrection
+
int a?3@201',6,;); int a?3@211',6,;7;
- . aEiF
?o ,rror orrection
+
8?4@2 11.1 , '.3 , 4.4 , 5.< ,
6.;7;
8?5@2 11.1 , '.3 , 4.4 , 5.< ,6.;7;
-
a03) A?3@
15) Bhat is the out"ut o& the &o$$owing "rogramsC
0a)
3333333B,DE+,3333333
#2<
sum2'1
33333333TFA*G HEI33333333
0b) use an9 in"ut 9ou want
"$ease enter height23
:$ease enter wi#th25
The resu$t215
0c)
1
'
3
4
5
6
7
<
;
1>
0#)
the sum 255
6e)
Ginclude Aiostream.h@
void main 6 )
H
int )46(
cout AA # ) 4 # AA ) AA endl(
cout AA # ) 4 # AA &&) AA endl(
cout AA # ) 4 # AA ) AA endl(
cout AA # ) 4 # AA )&& AA endl(
cout AA # ) 4 # AA ) AA endl(
I
16)
Brite a "rogram to "rint +u$ti"$ication tab$e &rom 1
to 5 as &o$$owing out"utC
-inc$u#e<iostream.h>
Joi# main0)
1
Knt K,=,";
)or0i21;i<25;=!!)
1
)or0=21;=<25;=!!)
1
:2=3K;
346
347
347
347
345
out<<";
out<<"LLLLLLLLLLLLL";
7
out<<en#$;
7
7
17) Brite a "rogram to com"ute the o"erations
&or two int numbers 0sum, subtract,
mu$ti"$ication, #i/i#e), using switch statement as
&o$$owing out"utC
-inc$u#e<iostream.h>
Joi# main0)
1
Knt 8,9;
)$oat r;
har o";
out<<"enter 8 then 9 then an9
o"eration0!,4,3,5)"<<en#$;
in>>8>>9>>o";
(witch 0o")
1
aseM!MC r28!9; breaN;
aseM4MC r2849; breaN;
aseM3MC r2839; breaN;
aseM5MC r2859; breaN;
Oe&au$tC cout<<"ba# o"eration";
7
out<<"r2"<<r<<en#$;
7
1<)
Brite a !! "rogram to rea# arra9 a o& n rea$
e$ements an# &in# their sum an# a/erage.
-inc$u#e<iostream.h>
Joi# main0)
1
onst int n25;
Knt K,n,
)$oat a?n@,sum, a/erage;
(um2>;
)or0i2>;i<a;i!!)
1
in>>a?i@;
(um!2a?i@;
7
A/erage2sum5n;
out<<"sum2"<<sum<<en#$;
out<<"a/erage2"<<a/erage<<en#$;
7
1;)
Brite a !! "rogram to &in# the sma$$est e$ement o& an
arra9 o& n rea$ e$ements.
-inc$u#e<iostream.h>
Joi# main0)
1
onst int n25
Knt K;
)$oat a?n@,sma$$;
)or0i2>;i<n;i!!)
in>>a?i@;
(ma$$2a?>@;
)or0i21;i<n;i!!)
K&0a?i@<sma$$)
(ma$$2a?i@;
out<<"sma$$2"<<sma$$<<en#$;
7