c++ codes part#06

Post on 06-Jan-2016

25 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

C++ CODES PART#06. Calculate area of a circle using a=pi*r*r. #include #include void main() { clrscr(); float rad; const float pi=3.14159f; coutrad; float area=pi*rad*rad; cout

TRANSCRIPT

C++ CODES PART#06

1

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

Calculate area of a circle using a=pi*r*r

#include<iostream.h>

#include<conio.h>

void main()

{ clrscr();

float rad;

const float pi=3.14159f;

cout<<"Enter Radious :";

2

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

CONTINUE…

cin>>rad;

float area=pi*rad*rad;

cout<<"Area is :"<<area<<endl;

getch();

}

3

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

Output…..

4

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

Do While loop

#include<constream.h>

void main()

{

clrscr();

int a;

a=1;

do

5

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

CONTINUE….

{

cout<<a<<endl;a++; }

while (a<11);

getch();}

6

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

Output…

7

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

Using power function

#include<constream.h>

#include<math.h>

void main()

{clrscr();

int a,b,c;

cout<<"enter the limit upto where you want the series";

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

8

Continue….

cin>>a;

for(b=1;b<=a;b++)

{c=pow(b,2);

cout<<c<<" ";}

cout<<"this series is the required one";

getch();}

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

9

Output…

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

10

Generate series as shown in the output…

#include<constream.h>

#include<math.h>

void main()

{clrscr();

int a,b,c;

cout<<"enter limit";

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

11

Continue…

cin>>a;

for(b=1;b<=a;b++)

{c=2*b*pow(-1,b);

cout<<c<<" ";}

cout<<"this series is the required one";

getch();}

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

12

Output….

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

13

Generate series as shown in the output…

#include<constream.h>

#include<math.h>

void main()

{clrscr();

int a,b,c;

cout<<"enter the last limit";

cin>>a;COPY RIGHT@

ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS

DEPARTMENT

14

Continue….

for(b=1;b<=a;b++){

c=2*b*pow(-1,b+1);

cout<<c<<" ";}

cout<<"hence this is the required series";

getch();}

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

15

Output…..

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

16

Generate series as shown in the output…

#include<constream.h>

#include<math.h>

void main()

{clrscr();

int a,b,c;

cout<<"enter the last limit";

cin>>a;COPY RIGHT@

ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS

DEPARTMENT

17

Continue…..

for(b=0;b<=a;b++)

{c=pow(3,b);

cout<<c<<" ";}

cout<<"this series is the required one";

getch();}

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

18

Output…..

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

19

While loop

#include<constream.h>

void main()

{clrscr();

int n;

while(n!=0)

cin>>n;

cout<<endl;

getch();} COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

20

Output…..

• User enters many numbers when he/she enters zero so program terminates

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT 21

Generate series as shown in output using while loop

#include<constream.h>

#include<math.h>

void main()

{

clrscr();

int a,b,r;

cout<<"plz enter your limit";COPY RIGHT@

ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS

DEPARTMENT22

Continue….

cin>>b;

a=1;

while(a<=b)

{r=2*a*pow(-1,a+1);

cout<<r<<" ";

a++;}

getch();}COPY RIGHT@

ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS

DEPARTMENT

23

Output…..

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

24

Generate series as shown in output using while loop

#include<constream.h>

#include<math.h>

void main()

{clrscr();

int a,b,r;

cout<<"enter limit";

cin>>b;COPY RIGHT@

ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS

DEPARTMENT

25

Continue….

a=0;

while(a<b)

{r=pow(3,a);

cout<<r<<" ";

a++;}

getch();}

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT 26

Output….

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

27

Generate series as shown in output using while loop

#include<constream.h>

#include<math.h>

void main()

{

clrscr();

int a,b,r;

cout<<"enter the limit";COPY RIGHT@

ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS

DEPARTMENT28

Continue…

cin>>b;

a=1;

while (a<=b)

{r=pow(a,2);

cout<<r<<" ";

a++;}

getch();}

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

29

Output…..

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

30

Do-while loop

#include<constream.h>

void main()

{clrscr();

long dividend,divisor;

char ch;

do

{COPY RIGHT@

ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS

DEPARTMENT31

Continue…

cout<<"enter dividend:";

cin>>dividend;

cout<<"enter divisor:";

cin>>divisor;

cout<<"quotient is "<<dividend/divisor;

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

32

Continue….

cout<< " , remainder is "<<dividend%divisor;

cout<<" \n do another?(y/n):";

cin>>ch;}

while (ch!='n');

getch();}

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

33

Output…..

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

34

CONCLUSION• NICE WORDINGS….• It is more difficult to stay on top than to get

there. The secret of success is that we never, never give up

• Barish ka Qatra Seepi or Sanp dono kay Munah mein girta hai Jab keh Sanp ussay Zehar bana deta hai aur Seep Usay Moti. Jis ka jaisa "Zarf" waisi Uss ki "Takhleeq".

COPY RIGHT@ ENGR.SABA MUGHAL FROM

COMPUTER SYSTEMS DEPARTMENT

35

top related