C++ CODES PART#06
description
Transcript of C++ CODES PART#06
![Page 1: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/1.jpg)
C++ CODES PART#06
1
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
![Page 2: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/2.jpg)
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
![Page 3: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/3.jpg)
CONTINUE…
cin>>rad;
float area=pi*rad*rad;
cout<<"Area is :"<<area<<endl;
getch();
}
3
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
![Page 4: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/4.jpg)
Output…..
4
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
![Page 5: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/5.jpg)
Do While loop
#include<constream.h>
void main()
{
clrscr();
int a;
a=1;
do
5
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
![Page 6: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/6.jpg)
CONTINUE….
{
cout<<a<<endl;a++; }
while (a<11);
getch();}
6
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
![Page 7: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/7.jpg)
Output…
7
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
![Page 8: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/8.jpg)
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
![Page 9: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/9.jpg)
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
![Page 10: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/10.jpg)
Output…
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
10
![Page 11: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/11.jpg)
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
![Page 12: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/12.jpg)
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
![Page 13: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/13.jpg)
Output….
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
13
![Page 14: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/14.jpg)
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
![Page 15: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/15.jpg)
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
![Page 16: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/16.jpg)
Output…..
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
16
![Page 17: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/17.jpg)
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
![Page 18: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/18.jpg)
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
![Page 19: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/19.jpg)
Output…..
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
19
![Page 20: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/20.jpg)
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
![Page 21: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/21.jpg)
Output…..
• User enters many numbers when he/she enters zero so program terminates
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT 21
![Page 22: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/22.jpg)
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
![Page 23: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/23.jpg)
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
![Page 24: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/24.jpg)
Output…..
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
24
![Page 25: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/25.jpg)
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
![Page 26: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/26.jpg)
Continue….
a=0;
while(a<b)
{r=pow(3,a);
cout<<r<<" ";
a++;}
getch();}
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT 26
![Page 27: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/27.jpg)
Output….
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
27
![Page 28: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/28.jpg)
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
![Page 29: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/29.jpg)
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
![Page 30: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/30.jpg)
Output…..
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
30
![Page 31: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/31.jpg)
Do-while loop
#include<constream.h>
void main()
{clrscr();
long dividend,divisor;
char ch;
do
{COPY RIGHT@
ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS
DEPARTMENT31
![Page 32: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/32.jpg)
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
![Page 33: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/33.jpg)
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
![Page 34: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/34.jpg)
Output…..
COPY RIGHT@ ENGR.SABA MUGHAL FROM
COMPUTER SYSTEMS DEPARTMENT
34
![Page 35: C++ CODES PART#06](https://reader036.fdocuments.us/reader036/viewer/2022062408/56813c8d550346895da6352a/html5/thumbnails/35.jpg)
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