Sei sulla pagina 1di 44

Index

1. wap to print welcome? 2. wap to print the addition , subtraction, multiplication and division of any given noi. using function? 3.wap to calculate simple interest? 4. wap to find out the greatest no. among given three no.s ? . wap to chech wheather the no is prime or not? !. wapo to print table of any given no. ? ". wap to calculate the factorial of given no. using while and do while loop? #. $ $$ $$$ $$$$ $$$ $$ $ %. &'()*)('& &'() )('& &'( &' & ('& '& &

1+. ,&- ./ 0/1. .2* 3/ I3 &11&4? 11. wap for the addition of two matrices? 12. wap for multiplication of matrices? 13. wap to count the length of given string? 14. wap to print the reverse of string? 1 . wap to chec5 wheather the given string is palandram or not? 1!. wap to calculate area of circle, rectangle, s6uare using polymorphism ? 1". wap to implement a multiple inheritance?

Q1.wap

to print welcome

#include <iostream.h> #include<conio.h> void main() { Cout<<"Welcome\n"; Getch(); }

/ut put

,elcome 7

Q.2 Operations On Two Integers /* ADD,SUB,DIV,MUL*/

#include<iostream.h> #include<conio.h> class a c ! "loat a, # $u lic% &oid 'etnum("loat n,"loat m) ! a*n# *m# + &oid $utnum(&oid) ! cout<<,-Irst no is%,<<a# cout<<,Second no is%,<< <<,.n,# + &oid sum("loat /,"loat 0) ! "loat 1# 1*/20# cout<< ,.nSUM IS%,<<1# + &oid di"("loat /,"loat 0) ! "loat $# $*/30# cout<<,.nDi""erence is%,<<$# + &oid mul("loat /,"loat 0) ! "loat 4# 4*/*0# cout<<,.nMulti$lication is%,<<4# + &oid di&("loat /,"loat 0) !

"loat r# r*//0# cout<<,.nDi&ision is%,<<r# + +# "loat main() ! a c a5,a6# clrscr()# a5.'etnum(6,7)# a6.sum(6,7)# a6.di"(6,7)# a6.di&(6,7)# a6.mul(6,7)# return(8)# +

Out put
Sum is :5 Difference is :-1 Division is :0.66666 !u"tip"ication is :6#

83.write a program to calculate the simple interest.

#include<iostream. h> #include<conio. > &oid main ( ) ! clrscr ( )# "loat $, r. t. SI# cout<<9enter the $rinc i$al &alue9# cin>>$# cout<<9enter the rate9# cin>>r# cout<<9enter the time9# cin>>t# SI*$*r*t/588# cout>>%9<<SI# 'etch ( )# !

O$T%$T

enter the $rinci$al &alue%:: enter 7rd num er;; the 7rd num er is 'reatest

Q. 4 Write a program to print which number is greater between 3 input numbers by outside class. Sol:// Prog. of greater number by class

#include<iostream.h> #include<conio.h> class greator { private: int a,b,c; public: void input void!; void print void!; "; void greator::input void! { cout<<# enter value of a$#; cin>>a; cout<<# enter value of b$#; cin>>b;

cout<<# enter value of c$#; cin>>c; " void greator::print void! { if a>b %% a>c! cout<<# a is greator#; if b>a %% b>c! cout<<# b is greator#; if c>a %% c>b! cout<<# c is greator#; " void main ! { clrscr !; greator &; &.input !; &.print !; "

/ut put

enter the value of a$ ' enter the value of b$ ( enter the value of c$ ) b is greater*

Q.5 &'IT( ) %'O*')! TO +,(+- %'I!( O' .OT


#include<iostream.h> #include<conio.h> void main ! { int n,+$,,i,s; clrscr !; cout<<#enter the no. you -ant to chec+:#; cin>>n; for i$.;i<$ n/.!;i//! {s$n0i; if s$$,! {+//; brea+; " " if +$$,! cout<<#no. is prime#; else cout<<#no. is not prime#; getch !; "

/9.-9.
enter the no. you -ant to chec+ :1( no. is prime enter the no. you -ant to chec+:) no. is not prime

Q.6 Write print a table of input number .


Sol:- //<ro'. o" ta
le 0 =hile loo$ #include<iostream.h> #include<conio.h> &oid main() ! clrscr()# int n,i*5,r# cout<<,enter num er%,# cin>>n# =hile (i<*58) ! r*n*i# cout<<r<<endl# i22# + +

Out put
enter the num er 7 7 > ? 56 5: 5; 65 6@ 6A 78B

Q. &rite a program to fin/ factoria" of given num0er using w1i"e "oop.

#include<iostream.h> #include<conio.h> &oid main() ! clrscr()# int n,"# "*5# cout<<,Cnter the the num er,# cin>>n# =hile(n>*5) ! "*"*n# n33# + cout<<,the "actorial is,<<"#

'etch()# +

Output
enter t1e num0er 5 factoria" is 120#

8.#.
2 2 2 2 2 2 2 2 22 222 22 2

#include<stdio.h> main() { int n, c,

!rint"("#nter num$er o" ro%s\n"); scan"("&d",'n); "or ( c ( ) ; c <( n ; c**) { "or ( ( ) ; <( c ; ** ) !rint"("+"); } !rint"("\n");

"or ( c ( n , - ; c >( . ; c,, ) { "or ( ( c ; >( . ; ,, ) !rint"("+"); } } !rint"("\n");

return .;

Out put

2 22 222 2222 222 22 2

8%. -1I3. .2I0 0*1I*0 :; &'()*)('& &'() &'( &' & )('& ('& '& &

#include<iostream.h> #include<conio.h> void main ! { clrscr !; int i,3,+,s; char a $ 456 ; for i$1;3<$';i//! { for s$7;s>$i;s88! { cout<< 9 : ; " for 3$1;3<$i;388! {

cout<<a; a//; " a//; for +$1;+<$i81;+//! { a88; cout<<a; " cout<<endl; " cout<<endl; "

/9.-9.

&'()*)('& &'() &'( &' & )('& ('& '& &7

8 1+ ,rite a program to sort an array.


#include<iostream.h> #include<conio.h> void main ! { ;lrscr !; int i,3,t,a<1,=; cout<<:enter the numbers:; for i$,;i<';i//! { ;in>>a<i=; " for i$,;i<';i//! { for 3$,;3<';3//! { if a<3/1=<a<3=! { t$a<3/1=; a<3/1=$a<3=; a<3=$t; " cout<<a<3=; " " getch !; "

/utput

enter ther the numbers ! 2 # % 1 the sorting list is 1 2 ! # %7

8 11 ,rie a program for addion of two matrices and display their sum in third matrix.
include<iostream.h> #include<conio.h> &oid main( ) ! int aD7E D7E , D7E D7E,cD7ED7E,i,F,G# clrscr()# cout<<HHenter element o" 5st matri/9# "or(i*8#i<7#i22) ! "or(F*8#F<7#F22) ! cin>>aDiEDiE# + ! cout<<HHenter element o" 6nd matri/9# "or(i*8#i<7#i22) ! "or(F*8#<7#F22) ! cin>> DiEDFE# + + "or(i*8#i<7#i22) ! "or(F*8#F<7#F22) !

cDiEDiE*aDiEDFE2DiEDFE# + + "or(i*8#i<7#i22) + "or(i*8#i<7#F22) ! cout<<9the sum o" matri/es is9<<cDiEDFE# + + 'etch( )#

Output

enter the elements o" 5st matri/ ? ; A > : @ 7 6 5 enter the el#ements o" 6ndmatri/ 5 6 7 @ : > A ; ? Ihe sum o" matri/es is 585858585858585858B

Q 12 &)% to fin/ t1e mu"tip"ication of two matrices. #include<stdio.h> #include<conio.h> &oid main() ! int aD58ED58E, D58ED58E,cD58ED58E,m,n,i,F,l,G# clrscr()# $rint"(,Cnter order o" the matri/ A %.n,)# scan"(,JdJd,,Km,Kn)# $rint"(,Cnter the elements o" the matri/ A %.n,)# "or(i*8#i<m#i22) ! "or(F*8#F<n#F22) ! scan"(,Jd,,KaDiEDFE)# + + $rint"(,Matri/ A %.n.n,)# "or(i*8#i<m#i22) ! "or(F*8#F<n#F22) ! $rint"(,Jd.t,,aDiEDFE)# + $rint"(,.n,)# + $rint"(,Cnter order o" the matri/ B %.n,)# scan"(,JdJd,,Kn,Kl)# $rint"(,Cnter the elements o" the matri/ B %.n,)# "or(i*8#i<n#i22) ! "or(F*8#F<l#F22) ! scan"(,Jd,,K DiEDFE)# + + $rint"(,Matri/ B %.n.n,)# "or(i*8#i<n#i22) !

"or(F*8#F<l#F22) ! $rint"(,Jd.t,, DiEDFE)# + $rint"(,.n,)# + $rint"(,Multi$lication o" the matri/ A and B %.n.n,)# "or(i*8#i<m#i22) ! "or(F*8#F<l#F22) ! cDiEDFE*8# "or(G*8#G<n#G22) ! cDiEDFE*cDiEDFE2aDiEDGE* DGEDFE# + $rint"(,Jd.t,,cDiEDFE)# + $rint"(,.n,)# + 'etch()# +

Output :

enter order o" the matri/ A % 6 7 enter the elements o" the matri/ A % 6 7 6 7 @ 5 matri/ A % 6 7 6 7 @ 5 enter order o" the matri/ B % 7 6 enter the elements o" the matri/ B % 5 6 @ 7 5 6 matri/ B % 5 6 @ 7 5 6 multi$lication o" the matri/ A and B % 5> 5A 68 68B

Q.13Write to create function of calculate length of string. Sol://Prog. of length of string function

#include<iostream.h> #include<conio.h> int len char n<',=!; void main ! { clrscr !; char &<',=; int l; cout<<#enter string#; cin>>&; l$len &!; cout<<l; " int len char n<',=!; { int i$l; -hile n<i=>$?@,?! { i//; " return i!;

" Aut put

enter strin/0cric et 12

Q14 Write to print reverse string without using function. Sol://Prog. of reverse sttring

#include<iostream.h> #include<conio.h> void main ! { clrscr !; char n<',=; int l$1,r; cout<<#enter string:#; cin>>n; -hile n<1=>$?@,?! { l//; " for r$1;r>$,;r88! { cout<<n<r=; " "

Lut $ut

enter t1e string: !a1es1 1se1am#

Q15 &)% to fin/ t1e given string is pa"in/rome or not.


Ans3 #include<stdio.h> #include<conio.h> #include<strin'.h> &oid main() ! char stD68E,rstD68E# int i,F# clrscr()# $rint"(,Cnter the strin' %,)# scan"(,Js,,st)# i*8# F*strlen(st)35# =hile(F>*8) ! rstDiE*stDFE# i22# F33# + rstDiE*M.8M# i"(strcm$(st,rst)**8) ! $rint"(,Strin' is $alindrome,)# + else ! $rint"(,Strin' is not $alindrome,)# + 'etch()# +

Output :

enter t1e string : nitin string is pa"in/rome#

Q16 . ,ap to calculate area using polymorphism


#include <iostream.h> #include <conio.h> class Briangle { float b,h; Briangle ! { b$,; h$,; " Briangle float &, float y! { b$&; h$y; " float 5rea ! { return ,.'2b2h; " " class ;ircle { float r; ;ircle ! { r$,; " ;ircle float &! { r$&; " float 5rea ! { return 7.C2r2r; " " class DEuare { float a;

DEuare ! { a$,; " DEuare float &! { a$&; " float 5rea ! { return a2a; " " class Fect { float l,b; Fect ! { l$,; b$,; " Fect float &, float y! { l$&; b$y; " float 5rea ! { return l2b; " " void main ! { clrscr !; Briangle t1 .,7!; cout << #5rea of triangle is # << t1.5rea !; ;ircle c 7!; cout << #5rea of circle is # << c.5rea !; DEuare s '!; cout << #5rea of DEuare is # << s.5rea !; Fect r C,)! cout << #5rea of Fectangle is# << r.5rea !; getch !; "

/ut put

area of triang"e: 3 area of circ"e : 50.23 area of s4uare: 25 area of rectang"e: 15#

8 1" ,1I.* & -1/<1&= /3 =9>.I->* I32*1I.&3(*

#include <iostream.h> #include<conio.h> class 5 " public: void f1 ! { cout<<:f1 in 5:<<endl; " ";class G " public: void f. ! { cout<<:f. in G:<<endl; " 9; class ;:public 5,public G { public: void fC ! cout<<:fC in ;:<<endl; "

"; void main ! { ; c; c.f1 !; c.f. !; c.fC !; getch !; "

/9.-9.

f1 in 5 f. in G fC in ;

%')+TI+)6 7I6( O. +88 %'O*')!S

S$9!ITT(D TO :%rof. %OO.)! S,)'!)

S$9!ITT(D 9:
*)'*I D)S,O')

Dept of .+S

9ranc1 ; !( 9(-1ST S(!

Potrebbero piacerti anche