SlideShare una empresa de Scribd logo
1 de 33
#include<iostream.h>
void main()
{
int x;
cin>>x;
if(x<=50)
x=x+1;
x=x+1;
if(x<=5 {
x++;
x++;
}
cout<<"x :"<<x<<endl;
}
#include<iostream.h>
void main ()
{
int r ;
cout<<" you can enter any value
to exit enter 0 ";
while ( r!=0)
{
cout<<"n";
cin>>r;
}
}
For addtation For aganst
Adobe Acrobat
Document
Adobe Acrobat
Document
ńȁȋơƧƾƷȂdzơ
ƨǤǴƥƨůŐdzơńƛƨ ƾǬǷ ǷC++
1.0
:ƧƾƷȂdzơǽǀǿƨȇƢȀǼƥ
♦Ʋ ơǂƥƨƥƢƬǯǺǺǰ ƬƬLJǷ Ƿ ǸC++.ƨǘȈLjƥ
♦.ƱơǂƻȍơȁDZƢƻƽȍơƩơǁƢƦǟǵơƾƼƬLJơǺ Ǻǰ ƬƬLJǷ Ǹ
♦ĿƨȈLJƢLJȋơƩƢǻƢȈƦdzơǝơȂǻƗȄǴǟǥǂǠƬƬLJC++.
♦ĿƨȈƥƢLjūơDzơȂǠdzơDZƢǠƬLJƛǺǺǰ ƬƬLJǷ Ǹ Ƿ ǸC++.
♦ĿƨȈǬƟȐǠdzơDzơȂǠdzơȄǴǟǥǂǠƬƬLJǷC++. OmerAhmedSaeed
Î-ÏȆǴȈdzƾdzơǦǴŭơ
#include iostream.h
ŐƬǠƫƨǤdzCƼǓƗǶƨǤdzǮdzƿȁŐǰdzƢȀƴƷǸƽƾǠƫȁƢēƢƦƬǰ Ƿ
ƾǼǟDzƢǠƬdzơǷƢȀǠǷǺǷDZȐƻƔƢnjǻƛƲƢǻǂƥǷƢǷƬȇǶDzƢǠƬdzơǷƨƥƢƬǰ ƥƩƢǨǴŭơƨȈǴȈdzƾdzơ
ƨȈLJƗǂdzơȁHeader FilesȆLjƫǸƆƢǔȇƗƩƢǨǴŠś ǔƬdzơǸInclude
Files
ƬȇǶǮdzƿĿƨǤdzCǺǷDZȐƻƧǁƢƦǠdzơƨȈdzƢƬdzơ
řǠƫDzȈ ŢǸǦǴŭơȄǴȈdzƾdzơiostream.hńƛƧǂǯơƿƣȂLJƢūơŕƷ
ŘLjƬȇƳǂƬǴdzǶ ǸƨǧǂǠǷȁƗƨŦǂƫƩƢȈǴǠdzơǸƨǏ ƢŬơDZƢƻƽȍƢƥƱơǂƻȍơȁ
ǚƷȐǻƗǹơǀǿǦǴŭơǾdzLJơǶƾȇƾƬdzơǸ.hǁƢǐ Ƭƻơºdzheader file
ƽƽơƾǟơśǴȈǼdzơƨǠƢƳƾȈǠLJ ƾŧ ơǂ ǟǷ Ǹ
1)Γή΋΋ΩΔΣΎδΔϋΎΒσΏΎδΤΞ ΎήΑΐΘ΋΋ϣ ϭ ϣϧϟϛarea = PI * r * r(
)Ύτ ΤϬ ϣϭϴcircumference = 2 * PI * r.(
)Ύ ήτ μ ΋Ζ ϋ΋Ϋ·ϫ ϒ ϧϥ ϤϠϗrΎδϱϭ ϳ (5.2΋΋ϥ ϭPI = 3.1415926
#include iostream.h
main()
{
float r, PI;
r = 5.2;
PI = 3.1415926;
coutarea =  PI * r * rn;
coutcircumference =  2 * PI * r;
}
2) σ ΎΧΩΞ ΎήΑΐΘ ΋Ϯ ϣϧϝ ϝ Ϲ ϛlength)νήϋ ϭ(width. τ ΘδϞ ϣϴ (
) τΘδ ΋Δ ΎΣϊΒτ ΐδΤϞ Ϥ ϓ ϳϭ ϳϭϴ ϟperimeter = 2*(length+width)) ΘΣΎδϪ ϣϭ(area=length*width(
#include iostream.h
main()
{
int length, width;
coutlength = ; cinlength;
coutwidth = ; cinwidth;
coutperimeter = 2*(length+width)n;
coutarea = length*width;
}
3)Ω΋ ϊΑέ΋ΕΎΟέΩΓ΋΋ή Ξ ΎήΑΐΘ ΋Ϯϣ ϣϧϘϟ ϛm1, m2, m3, m4(
) Ϊό ΋ϊΒτ ΐδΤ ΛϤ ϳϭ ϳϢϝ ϟavg = (m1+m2+m3+m4)/4(
#include iostream.h
main()
{
int m1, m2, m3, m4;
coutEnter marks n;
cinm1m2m3m4;
coutavg =  (m1+m2+m3+m4)/4;
}
4ήτδ ΋ γ΋ΔϋΎΒτΞ ΎήΑΐΘ΋΋ϲϓϚϤ ϣϧϟ ϟϛ΍ϭϝ ϷΔ Π ΋Ϭ Ϧϣϟήδ ΍ϯ ϴϟ΋ϋ΋΋ϲϓϚϧ ϮϨϭ ˬςγ ϭήτδ ΋ϟΚ ΎΜ΍ϟϟΔ δ Π ΋Ϩ ϭϴ ϟ ˬ
΋Δ Π ΋ϰϨϤ Ϭ ϲϓϴϟ ϟ
#include iostream.h
main()
{
coutAbdulla Awad nnttt;
coutBaitBoss zone ttt Yemeni;
}
α1ΎΩΪϋΔΤΤλΩ΋Ϊϋ΋Ε΋Ϋ Θ μ ήλΎ ϋΓ΋΋ή Ξ ΎήΑΐΘ ΋ϫ Ϧ ϓϮϔϣ Ϩ ϣϧϴ ϴϘ ϟ ϛ . ΋Ϊ ΋΋ΪΨΘγΎΑϭϝ ϟϡ5ΛϢ .
)Δ Ο ΰ ΋ήλΎ ό ΋ΔϋΎΒσϭ Ϩϴ ϟ ϟEven)Δ Ωή ΋ϳ ϔϭϟ (Odd.Δ μϓϮϔϣϞϜϟ(
#include iostream.h
read(int ar[]) {
coutEnter 5 numbers:;
for(int i=0; i=4; i++)
cinar[i];
}
isEven(int x) {
if(x % 2 == 0) return 1;
return 0;
}
isOdd(int x) {
return (!isEven(x));
}
printEven(int ar[]) {
coutEven numbers: ;
for(int i=0; i=4; i++)
if(isEven(ar[i])) coutar[i] ;
coutendl;
}
printOdd(int ar[]) {
coutOdd numbers: ;
for(int i=0; i=4; i++)
if(isOdd(ar[i])) coutar[i] ;
coutendl;
}
main() {
int a[5];
read(a);
printEven(a);
printOdd(a);
int b[5];
read(b);
printEven(b);
printOdd(b);
}
#includeiostream
using namespace std;
int larger(int,int);
void main()
{
int a=2,b=6;
coutlarger(a,b)is largeendl;
}
int larger(int x,int y)
{
if(xy)
return x;
else
return y;
}
#includeiostream
using namespace std;
int larger();
void main()
{
coutlarger()is largerendl;
}
int larger()
{
int x=2,int y=6;
if(xy)
return x;
else
return y;
}
1)
#includeiostream
using namespace std;
int larger();
void main()
{
coutlarger()is largerendl;
}
int larger()
{
int x=2,int y=6;
if(xy)
return x;
else
return y;
}
#includeiostream
using namespace std;
void line(char,int);
int main()
#include iostream.h
void main()
{
int num1,num2;
char ch;
cinnum1;
coutya doye daxel bka;
cinnum2;
coutenter aletter;
cinch;
if((ch=='A')||(ch=='a'))
coutdiffrence is :num1+num2endl;
else
coutInvalid letterendl;
}
This is number additation and litter
#include iostream.h
void main()
{
int x;
for(x=1; x=15 ;
x=x+2)
coutxendl;
}
1,3,5,7,9,11,13,15
#include iostream.h
void main()
{
for(int x=2; x=10 ; x++)
coutxendl;
}
2,3,….10
#include iostream.h
void main()
{
int x,i;
cin x;
i=2;
while (xi)
{
if (x%i==0)
{
coutthe number in not prime;
i=x+1;
}
else
if(x % i !=0)
i++;
}
if(x==i)
coutthe number is prime;
}
#includeiostream.h
void main()
{
int a,b,c,i;
char s=' ';
a=b=1;
coutasbs;
for(i=3;i=10;i++)
{
c=a+b;
coutcs;
a=b;
b=c;
}
}
1 1 2 5 8 13 21 34 55
Fibonacci Series
#includeiostream.h
void main()
{
int a,b,c,i,n;
char s=' ';
a=b=1;
cinn;
coutasbs;
for(i=3;i=n;i++)
{
c=a+b;
coutcs;
a=b;
b=c;
}}
insert n 1 1 2 5 8 13 21 34 55
#includeiostream.h
void main ()
{
float sum=0,average,count;
count=0;
for(float i=10.5;i=99.5;i=i+10)
{
sum=sum+i;
count++;
}
coutsumendl;
average=sum/count;
coutaverageendl;
}
#includeiostream.h
void main ()
{
int flag=0,n;
cinn;
for(int i=2;inflag==0;i++)
if (n%i==0)
flag=1;
if(flag==1)
coutprimeendl;
else
cout not primeendl;
}
#includeiostream.h
void main ()
{
int flag=0,n;
cinn;
for(int i=0;in;i++)
{
if (n%i==0)
flag=1;
}
if(flag==0)
coutprimeendl;
else
cout not primeendl;
}
#include iostream.h
int sum(int);
void main ()
{
int x ;
cout sumion is :- sum (x) ;
}
int sum (int a)
{
int su =0 ;
for(int i=1 ; i=50 ;i++)
su+=i ;
return su ;
}
#includeiostream.h
void main ()
{
int sum=0;
for(int i=0; i=50; i++)
{
sum+=i;
}
cout the sum of number from 0
to 50 is endl;
coutsumendl;
}
#include iostream.h
void main ()
{
int x ;
coutEnter one number  't';
cinx ;
for (int i=1 ;i=x ;i++)
{
for (int j=1 ;j=x ;j++)
couti*j = i*j
endl ;
cout endl ;
}
coutendl ;
cout-------------- ;
}
‫ن*ن‬ ‫ت‬ ‫جيكه‬ ‫دي‬ ‫ضربي‬ ‫جدول‬
#include iostream.h
int po (int ,int) ;
int main ()
{
int x ,y ;
coutEnter x ,y  ;
cinxy ;
coutnx to po y=po(x,y)endl ;
return 0 ;
}
int po (int a , int b )
{
int p= 1 ;
for (int i=1 ; i=b ;i++)
p=p*a ;
return p ;
}
Enter x,y 5 6
X to po y =15625
#include  iostream.h
void main ( )
}
int x;
cin x;
cout x endl;
cout x *2endl;
cout x *3endl;
cout x *4endl;
cout x *5endl;
cout x *6endl;
cout x *7endl;
cout x *8endl;
cout x *9endl;
{
#include iostream.h
void main ()
{
int x ;
coutEnter number x  endl ;
cinx ;
if ( x%2 == 0)
coutNumber is even:-  x ;
else if ( x%2 != 0)
coutNumber is odd :- x ;
}
#include iostream.h
void main ( )
{
// an integer number
int Num,i;
// numebr of numbers
int Num_Num;
// total of numbers
int Sum = 0;
cout  Enter the number of numbers : ;
// get the number of numbers from user
cin  Num_Num;
// loop from 1 to Num_Num.
for (int Counter = 1; Counter = Num_Num ; i++ )
{
cout  Enter number (  Counter  ) :;
// get the number from user
cin  Num;
// put the number in sum
Sum += Num;
} // end for
// print the result
cout  The Result is :   Sum ;
} // end main
#include iostream.h
int Pluse ( int, int );
int Minus ( int, int );
int Div ( int, int );
int Mult ( int, int );
void main ( )
{
int Fir_Num;
int Sec_Num;
char Ope;
cout  Enter the first number : ;
cin  Fir_Num;
cout  Enter the second number : ;
cin  Sec_Num;
cout  Enter ur operation : ;
cin  Ope;
switch (Ope)
{
case ' + ' :
cout  The result is : ;
break;
case ' - ' :
cout  The result is : 
 Minus ( Fir_Num, Sec_Num );
break;
case '*' :
cout  The result is : 
 Mult ( Fir_Num, Sec_Num );
case ' / ' :
cout  The result is : 
 Div ( Fir_Num , Sec_Num );
break ;
default :
cout  Sorry ur operation is wrong ;
}
}
int Pluse ( int x, int y )
{
return x + y ;
}
int Minus ( int x, int y )
{
return x - y;
}
int Div ( int x, int y )
{
if ( y == 0 )
{
cout  Error division by zero ;
return 0;
}
else
return x / y;
}
int Mult ( int x, int y )
{
return x * y ;
}
#include iostream.h
void main( )
{
int Fir_Num;
int Sec_Num;
cout  Enter the first number :  ;
cin  Fir_Num ;
cout  Enter the second number :
 ;
cin  Sec_Num;
cout  The Result is :  
Fir_Num + Sec_Num ;
}
#include iostream.h
void main ( )
{
int Num_Of_Sub;
int Grade;
int Total = 0;
int Average;
cout  Plz enter number of subjects : ;
cin  Num_Of_Sub;
for (int Counter = 1; Counter = Num_Of_Sub; Counter++)
{
cout  Enter grade number (  Counter  ) :  ;
cin  Grade;
if (Grade = 50  Grade = 100)
Total += Grade;
else
{
cout  Sorry ...grade is out of range !!!!! try againn;
Counter--;
}
}
Average = Total / Num_Of_Sub ;
cout  The average is :   Average ;
}
#includeiostream.h
void main()
{
long d1 , d2;
char let;
do{
coutenter the first numbern;
cind1;
coutenter the second numbern;
cind2;
cout the result of multiple two
numbers is :n;
coutd1*d2;
coutn if you want to do again press
any letter or number unless a n;
cinlet;
coutn;
}while(let!='a');
}
B
y
t
h
is
y
ou
c
a
n
(n
u
m
*n
u
m
)
a
n
d
y
ou
a
g
a
in
a
n
y
t
im
e
in
t
e
r
(c
h
,n
u
m
)
#includeiostream.h
void main ()
{
int k;
cout  enter your number : n ;
cin k;
if ( k50)
cout the number is less than 50
;
else
coutava darkatendl;
}
If and else
#include iostream.h
void main()
{
int z,y;
cout Inter your longendl;
cin z ;
cout Inter friend's longendl;
cin y;
cout --------------------endl;
if(zy)
{
cout You longerendl;
cout Your long is zendl;
coutendl;
cout  The average longs are ;
cout (z+y)/2;
}
else
{
cout Your friend is longerendl;
cout He's long is yendl;
cout y*2 = y*2endl;
cout y/2 = y/2;
}
}
#includeiostream.h
void main()
{
for(int i=1;i7;i++)
{
for(int j=1;j10;j++)
{
cout*;
}
coutn;
}
}
**********
**********
**********
**********
**********
**********
**********
#includeiostream.h
void main()
{
int sum;
for(int i=1;i=8;i++)
{
for(int j=i;j=9;j++)
{
cout=;
}
sum+=j;
coutn;
}
} ========
=======
======
=====
====
===
==
=
+
++
+++
+++++
++++++
+++++++
++++++++
#include iostream.h
void main()
{
int x;
cin x;
switch (x)
{
case 1:
cout welcomeendl;
break;
case 2:
cout hello studentendl;
break;
case 3:
cout introdaction to c++endl;
break;
default:
cout bye bye;
}
}
cout its a Saturnendl;
break;
case 7:
cout its a URANUSendl;
break;
case 8:
cout its a NEPTUNEendl;
break;
case 9:
cout its a PLUTOendl;
break;
case 10:
cout its a senda endl;
break;
default:
cout err no plant to resemble this
numberendl;
break;
}
}
#include iostream.h
void main()
{
int x;
cout  inter number a planet  endl;
cin x;
switch (x)
{
case 1:
cout its a Mercuryendl;
break;
case 2:
cout its a Venusendl;
break;
case 3:
cout its a earthendl;
break;
case 4:
cout its a Marsendl;
break;
case 5:
cout its a Jupiterendl;
break;
case 6:
About switch
#includeiostream.h
main()
{
int x;
coutenter the decimal number:;
cin x;
while(x=12)
{switch(x)
{
case 1:
{coutIendl;
coutenter the decimal number:;}
break;
case 2:
{coutIIendl;
coutenter the decimal number:;}
break;
case 3:
{coutIIIendl;
coutenter the decimal number:;}
break;
case 4:
{coutIVendl;
cout enter the decimal number:;}
break;
case 5:
{coutVendl;
coutenter the decimal number:;}
break;
case 6:
{coutVIendl;
coutenter the decimal number:;}
case 8:
{coutVIIIendl;
coutenter the decimal number;}
break;
case 9:
{coutIXendl;
coutenter the decimal number;}
break;
case 10:
{coutXIendl;
coutenter the decimal number;}
break;
case 11:
{coutXIIendl;
coutenter the decimal number;}
break;
case 12:
{coutXIIIendl;
coutenter the decimal number:;}
break;
default:
coutNOOOO;
break;
}
cinx;
}
}
break;
case 7:
{coutVIIendl;
coutenter the decimal number:;}
break;
#include iostream.h
void main()
{
int x, sum;
sum = 0;
do
{
cinx;
sum+=x;
}while (x!=0);
coutsum of number
is =sum;
}
#include iostream.h
void main ()
{
for (char x=65;x=90;x++)
cout     x;
}
a……..z
#include iostream.h
void main ()
{
for (int x='A' ;x='Z' ;x++)
cout     x;
}
65……..90
#include iostream.h
void main ()
{
float L, M;
char ch;
do
{
cout  nEnter L: ;
cin  L;
cout  Enter M: ;
cin  M;
cout  nL+M=   L+M;
cout  nL-M=   L-M;
cout  nL*M=   L*M;
if (M != 0)
cout  nL/M=   L/M;
cout   n Do Again (y/n): ;
cin  ch;
}
while (ch != 'n');
}
Other more programming
W
hile for again
#include iostream.h
void main ( )
{
for (int i = 0; i  15; i++)
cout  i * i   ;
}
#include iostream.h
void main ()
{
int x = 10;
cout   x =   x  endl;
cout  n ++x =   ++x  endl;
cout   x++ =   x++  endl;
cout  n x =   x  endl ;
cout  n --x =   --x  endl;
cout   x-- =   x--  endl;
cout  n x =   x  endl ;
}
For information
#include iostream.h
#include math.h
void main ()
{
int x, y, P ;
cout   Enter a number:  ;
cin  x ;
cout   Enter a power :  ;
cin  y ;
P = pow (x,y) ;
cout   The result is :   P 
endl ;
}
#include iostream.h
#include math.h
void main ( )
{
float num, ans;
cout   Enter a number: ;
cin  num;
ans = sqrt(num) ;
cout   square root is:   ans  endl;
}
Calculus example
#include iostream.h
int sqr (int n)
{
int r;
r=n*n;
return r;
}
void main()
{
int k;
cink;
coutsqr(k)endl;
}
Function
#include iostream.h
int sqr (int);
void main()
{
int k;
cink;
coutsqr(k)endl;
}
int sqr (int n)
{
int r;
r=n*n;
return r;
}
#include iostream.h
void fun()
{
int i=10;
coutiendl;
}
void main()
{
int i=5;
fun();
coutiendl;
}
10
5
#include iostream.h
void azo()
{
int i=10;
coutiendl;
}
void main()
{
int i=5;
coutiendl;
azo();
coutiendl;
}
5
10
5
#include iostream.h
void azo(int n)
{
n++;
coutnendl;
}
void main()
{
int n=5;
azo(n);
coutnendl;
}
6
5
#include iostream.h
void main()
{
int x=100,y=5;
int temp;
temp=x;
x=y;
y=temp;
coutxyendl;
}
#includeiostream.h
int fact (int);
void main ()
{
int sum=0,i,n;
cinn;
for(i=0;i=n;i++)
sum+=fact(i);
coutsum = sum;
}
int fact (int n)
{
int i,s;
s=1;
for(i=n;i=1;i--)
s*=i;
return s;
}
2—sum=4,3—sum=10
4—sum=34,5—sum=154
Sum = 1 + x^1 + x^2 + x^3 + x^4 + x^5
#includeiostream.h
#includemath.h
void main()
{
int sum=0,x,i;
cinx;
for(i=5;i=1;i--)
sum+=pow(x,i);
coutsum;
}
#include stdio.h 
void main ( )
{
FILE * f;
f=fopen(d:stdudent.txt,azad
lesson);
fprintf(f, welcome to C++);
fclose(f);
}
file #includeiostream.h
#includestdio.h
#includestdlib.h
void main()
{
FILE *out;
int score;
if((out=fopen(test.txt,w))==NULL)
{
coutcan not open filen;
exit(-1);
}
coutenter a test score (0 terminate input);
cinscore;
while(score !=0)
{
fprintf(out,%dn,score);
cout enter anather score;
cinscore;
}
fclose(out);
}

Más contenido relacionado

La actualidad más candente

Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
Jeff Tu Pechito
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
Swarup Kumar Boro
 

La actualidad más candente (20)

CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
Useful c programs
Useful c programsUseful c programs
Useful c programs
 
Ejercicios de programacion
Ejercicios de programacionEjercicios de programacion
Ejercicios de programacion
 
Programming with GUTs
Programming with GUTsProgramming with GUTs
Programming with GUTs
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
Clean Coders Hate What Happens To Your Code When You Use These Enterprise Pro...
 
Pointer
PointerPointer
Pointer
 
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
(Rx).NET' way of async programming (.NET summit 2017 Belarus)(Rx).NET' way of async programming (.NET summit 2017 Belarus)
(Rx).NET' way of async programming (.NET summit 2017 Belarus)
 
C++ L01-Variables
C++ L01-VariablesC++ L01-Variables
C++ L01-Variables
 
Data structure
Data structureData structure
Data structure
 
Student Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final ProjectStudent Data Base Using C/C++ Final Project
Student Data Base Using C/C++ Final Project
 
What We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit TestingWhat We Talk About When We Talk About Unit Testing
What We Talk About When We Talk About Unit Testing
 
C sharp 8
C sharp 8C sharp 8
C sharp 8
 
c++ program for Railway reservation
c++ program for Railway reservationc++ program for Railway reservation
c++ program for Railway reservation
 
Functional C++
Functional C++Functional C++
Functional C++
 
Implementing string
Implementing stringImplementing string
Implementing string
 
C++ assignment
C++ assignmentC++ assignment
C++ assignment
 
P1
P1P1
P1
 
Pointers
PointersPointers
Pointers
 
C Code and the Art of Obfuscation
C Code and the Art of ObfuscationC Code and the Art of Obfuscation
C Code and the Art of Obfuscation
 

Destacado (8)

Maths project for class 10 th
Maths project for class 10 thMaths project for class 10 th
Maths project for class 10 th
 
STATISTICS: Normal Distribution
STATISTICS: Normal Distribution STATISTICS: Normal Distribution
STATISTICS: Normal Distribution
 
Introduction to statistics
Introduction to statisticsIntroduction to statistics
Introduction to statistics
 
Statistics Math project class 10th
Statistics Math project class 10thStatistics Math project class 10th
Statistics Math project class 10th
 
Basic Statistical Concepts and Methods
Basic Statistical Concepts and MethodsBasic Statistical Concepts and Methods
Basic Statistical Concepts and Methods
 
Statistics
StatisticsStatistics
Statistics
 
Introduction to statistics...ppt rahul
Introduction to statistics...ppt rahulIntroduction to statistics...ppt rahul
Introduction to statistics...ppt rahul
 
Introduction To Statistics
Introduction To StatisticsIntroduction To Statistics
Introduction To Statistics
 

Similar a Cpp c++ 1

I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
shreeaadithyaacellso
 
ch5_additional.ppt
ch5_additional.pptch5_additional.ppt
ch5_additional.ppt
LokeshK66
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
HIMANSUKUMAR12
 
basic programs in C++
basic programs in C++ basic programs in C++
basic programs in C++
Arun Nair
 
Please use the code below and make it operate as one program- Notating.pdf
Please use the code below and make it operate as one program- Notating.pdfPlease use the code below and make it operate as one program- Notating.pdf
Please use the code below and make it operate as one program- Notating.pdf
seoagam1
 

Similar a Cpp c++ 1 (20)

Cpp c++ 2
Cpp c++ 2Cpp c++ 2
Cpp c++ 2
 
C++ Programming - 2nd Study
C++ Programming - 2nd StudyC++ Programming - 2nd Study
C++ Programming - 2nd Study
 
C++ L03-Control Structure
C++ L03-Control StructureC++ L03-Control Structure
C++ L03-Control Structure
 
10 template code program
10 template code program10 template code program
10 template code program
 
oodp elab.pdf
oodp elab.pdfoodp elab.pdf
oodp elab.pdf
 
C++ Programming - 1st Study
C++ Programming - 1st StudyC++ Programming - 1st Study
C++ Programming - 1st Study
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
ch5_additional.ppt
ch5_additional.pptch5_additional.ppt
ch5_additional.ppt
 
Computer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdfComputer_Practicals-file.doc.pdf
Computer_Practicals-file.doc.pdf
 
C++ practical
C++ practicalC++ practical
C++ practical
 
basic programs in C++
basic programs in C++ basic programs in C++
basic programs in C++
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
Please use the code below and make it operate as one program- Notating.pdf
Please use the code below and make it operate as one program- Notating.pdfPlease use the code below and make it operate as one program- Notating.pdf
Please use the code below and make it operate as one program- Notating.pdf
 
project3
project3project3
project3
 
Go vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoFGo vs C++ - CppRussia 2019 Piter BoF
Go vs C++ - CppRussia 2019 Piter BoF
 
Abebe1
Abebe1Abebe1
Abebe1
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Último (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 

Cpp c++ 1

  • 1.
  • 2. #include<iostream.h> void main() { int x; cin>>x; if(x<=50) x=x+1; x=x+1; if(x<=5 { x++; x++; } cout<<"x :"<<x<<endl; } #include<iostream.h> void main () { int r ; cout<<" you can enter any value to exit enter 0 "; while ( r!=0) { cout<<"n"; cin>>r; } } For addtation For aganst
  • 3. Adobe Acrobat Document Adobe Acrobat Document ńȁȋơƧƾƷȂdzơ ƨǤǴƥƨůŐdzơńƛƨ ƾǬǷ ǷC++ 1.0 :ƧƾƷȂdzơǽǀǿƨȇƢȀǼƥ ♦Ʋ ơǂƥƨƥƢƬǯǺǺǰ ƬƬLJǷ Ƿ ǸC++.ƨǘȈLjƥ ♦.ƱơǂƻȍơȁDZƢƻƽȍơƩơǁƢƦǟǵơƾƼƬLJơǺ Ǻǰ ƬƬLJǷ Ǹ ♦ĿƨȈLJƢLJȋơƩƢǻƢȈƦdzơǝơȂǻƗȄǴǟǥǂǠƬƬLJC++. ♦ĿƨȈƥƢLjūơDzơȂǠdzơDZƢǠƬLJƛǺǺǰ ƬƬLJǷ Ǹ Ƿ ǸC++. ♦ĿƨȈǬƟȐǠdzơDzơȂǠdzơȄǴǟǥǂǠƬƬLJǷC++. OmerAhmedSaeed Î-ÏȆǴȈdzƾdzơǦǴŭơ #include iostream.h ŐƬǠƫƨǤdzCƼǓƗǶƨǤdzǮdzƿȁŐǰdzƢȀƴƷǸƽƾǠƫȁƢēƢƦƬǰ Ƿ ƾǼǟDzƢǠƬdzơǷƢȀǠǷǺǷDZȐƻƔƢnjǻƛƲƢǻǂƥǷƢǷƬȇǶDzƢǠƬdzơǷƨƥƢƬǰ ƥƩƢǨǴŭơƨȈǴȈdzƾdzơ ƨȈLJƗǂdzơȁHeader FilesȆLjƫǸƆƢǔȇƗƩƢǨǴŠś ǔƬdzơǸInclude Files ƬȇǶǮdzƿĿƨǤdzCǺǷDZȐƻƧǁƢƦǠdzơƨȈdzƢƬdzơ řǠƫDzȈ ŢǸǦǴŭơȄǴȈdzƾdzơiostream.hńƛƧǂǯơƿƣȂLJƢūơŕƷ ŘLjƬȇƳǂƬǴdzǶ ǸƨǧǂǠǷȁƗƨŦǂƫƩƢȈǴǠdzơǸƨǏ ƢŬơDZƢƻƽȍƢƥƱơǂƻȍơȁ ǚƷȐǻƗǹơǀǿǦǴŭơǾdzLJơǶƾȇƾƬdzơǸ.hǁƢǐ Ƭƻơºdzheader file ƽƽơƾǟơśǴȈǼdzơƨǠƢƳƾȈǠLJ ƾŧ ơǂ ǟǷ Ǹ 1)Γή΋΋ΩΔΣΎδΔϋΎΒσΏΎδΤΞ ΎήΑΐΘ΋΋ϣ ϭ ϣϧϟϛarea = PI * r * r( )Ύτ ΤϬ ϣϭϴcircumference = 2 * PI * r.( )Ύ ήτ μ ΋Ζ ϋ΋Ϋ·ϫ ϒ ϧϥ ϤϠϗrΎδϱϭ ϳ (5.2΋΋ϥ ϭPI = 3.1415926 #include iostream.h main() { float r, PI; r = 5.2; PI = 3.1415926; coutarea = PI * r * rn; coutcircumference = 2 * PI * r; } 2) σ ΎΧΩΞ ΎήΑΐΘ ΋Ϯ ϣϧϝ ϝ Ϲ ϛlength)νήϋ ϭ(width. τ ΘδϞ ϣϴ ( ) τΘδ ΋Δ ΎΣϊΒτ ΐδΤϞ Ϥ ϓ ϳϭ ϳϭϴ ϟperimeter = 2*(length+width)) ΘΣΎδϪ ϣϭ(area=length*width( #include iostream.h main() { int length, width; coutlength = ; cinlength; coutwidth = ; cinwidth; coutperimeter = 2*(length+width)n; coutarea = length*width; } 3)Ω΋ ϊΑέ΋ΕΎΟέΩΓ΋΋ή Ξ ΎήΑΐΘ ΋Ϯϣ ϣϧϘϟ ϛm1, m2, m3, m4( ) Ϊό ΋ϊΒτ ΐδΤ ΛϤ ϳϭ ϳϢϝ ϟavg = (m1+m2+m3+m4)/4( #include iostream.h main() { int m1, m2, m3, m4; coutEnter marks n; cinm1m2m3m4; coutavg = (m1+m2+m3+m4)/4; } 4ήτδ ΋ γ΋ΔϋΎΒτΞ ΎήΑΐΘ΋΋ϲϓϚϤ ϣϧϟ ϟϛ΍ϭϝ ϷΔ Π ΋Ϭ Ϧϣϟήδ ΍ϯ ϴϟ΋ϋ΋΋ϲϓϚϧ ϮϨϭ ˬςγ ϭήτδ ΋ϟΚ ΎΜ΍ϟϟΔ δ Π ΋Ϩ ϭϴ ϟ ˬ ΋Δ Π ΋ϰϨϤ Ϭ ϲϓϴϟ ϟ #include iostream.h main() { coutAbdulla Awad nnttt; coutBaitBoss zone ttt Yemeni; } α1ΎΩΪϋΔΤΤλΩ΋Ϊϋ΋Ε΋Ϋ Θ μ ήλΎ ϋΓ΋΋ή Ξ ΎήΑΐΘ ΋ϫ Ϧ ϓϮϔϣ Ϩ ϣϧϴ ϴϘ ϟ ϛ . ΋Ϊ ΋΋ΪΨΘγΎΑϭϝ ϟϡ5ΛϢ . )Δ Ο ΰ ΋ήλΎ ό ΋ΔϋΎΒσϭ Ϩϴ ϟ ϟEven)Δ Ωή ΋ϳ ϔϭϟ (Odd.Δ μϓϮϔϣϞϜϟ( #include iostream.h read(int ar[]) { coutEnter 5 numbers:; for(int i=0; i=4; i++) cinar[i]; } isEven(int x) { if(x % 2 == 0) return 1; return 0; } isOdd(int x) { return (!isEven(x)); } printEven(int ar[]) { coutEven numbers: ; for(int i=0; i=4; i++) if(isEven(ar[i])) coutar[i] ; coutendl; } printOdd(int ar[]) { coutOdd numbers: ; for(int i=0; i=4; i++) if(isOdd(ar[i])) coutar[i] ; coutendl; } main() { int a[5]; read(a); printEven(a); printOdd(a); int b[5]; read(b); printEven(b); printOdd(b); } #includeiostream using namespace std; int larger(int,int); void main() { int a=2,b=6; coutlarger(a,b)is largeendl; } int larger(int x,int y) { if(xy) return x; else return y; } #includeiostream using namespace std; int larger(); void main() { coutlarger()is largerendl; } int larger() { int x=2,int y=6; if(xy) return x; else return y; } 1) #includeiostream using namespace std; int larger(); void main() { coutlarger()is largerendl; } int larger() { int x=2,int y=6; if(xy) return x; else return y; } #includeiostream using namespace std; void line(char,int); int main()
  • 4. #include iostream.h void main() { int num1,num2; char ch; cinnum1; coutya doye daxel bka; cinnum2; coutenter aletter; cinch; if((ch=='A')||(ch=='a')) coutdiffrence is :num1+num2endl; else coutInvalid letterendl; } This is number additation and litter
  • 5. #include iostream.h void main() { int x; for(x=1; x=15 ; x=x+2) coutxendl; } 1,3,5,7,9,11,13,15 #include iostream.h void main() { for(int x=2; x=10 ; x++) coutxendl; } 2,3,….10 #include iostream.h void main() { int x,i; cin x; i=2; while (xi) { if (x%i==0) { coutthe number in not prime; i=x+1; } else if(x % i !=0) i++; } if(x==i) coutthe number is prime; }
  • 6. #includeiostream.h void main() { int a,b,c,i; char s=' '; a=b=1; coutasbs; for(i=3;i=10;i++) { c=a+b; coutcs; a=b; b=c; } } 1 1 2 5 8 13 21 34 55 Fibonacci Series #includeiostream.h void main() { int a,b,c,i,n; char s=' '; a=b=1; cinn; coutasbs; for(i=3;i=n;i++) { c=a+b; coutcs; a=b; b=c; }} insert n 1 1 2 5 8 13 21 34 55
  • 7. #includeiostream.h void main () { float sum=0,average,count; count=0; for(float i=10.5;i=99.5;i=i+10) { sum=sum+i; count++; } coutsumendl; average=sum/count; coutaverageendl; }
  • 8. #includeiostream.h void main () { int flag=0,n; cinn; for(int i=2;inflag==0;i++) if (n%i==0) flag=1; if(flag==1) coutprimeendl; else cout not primeendl; }
  • 9. #includeiostream.h void main () { int flag=0,n; cinn; for(int i=0;in;i++) { if (n%i==0) flag=1; } if(flag==0) coutprimeendl; else cout not primeendl; }
  • 10. #include iostream.h int sum(int); void main () { int x ; cout sumion is :- sum (x) ; } int sum (int a) { int su =0 ; for(int i=1 ; i=50 ;i++) su+=i ; return su ; } #includeiostream.h void main () { int sum=0; for(int i=0; i=50; i++) { sum+=i; } cout the sum of number from 0 to 50 is endl; coutsumendl; }
  • 11. #include iostream.h void main () { int x ; coutEnter one number 't'; cinx ; for (int i=1 ;i=x ;i++) { for (int j=1 ;j=x ;j++) couti*j = i*j endl ; cout endl ; } coutendl ; cout-------------- ; } ‫ن*ن‬ ‫ت‬ ‫جيكه‬ ‫دي‬ ‫ضربي‬ ‫جدول‬ #include iostream.h int po (int ,int) ; int main () { int x ,y ; coutEnter x ,y ; cinxy ; coutnx to po y=po(x,y)endl ; return 0 ; } int po (int a , int b ) { int p= 1 ; for (int i=1 ; i=b ;i++) p=p*a ; return p ; } Enter x,y 5 6 X to po y =15625
  • 12. #include iostream.h void main ( ) } int x; cin x; cout x endl; cout x *2endl; cout x *3endl; cout x *4endl; cout x *5endl; cout x *6endl; cout x *7endl; cout x *8endl; cout x *9endl; {
  • 13. #include iostream.h void main () { int x ; coutEnter number x endl ; cinx ; if ( x%2 == 0) coutNumber is even:- x ; else if ( x%2 != 0) coutNumber is odd :- x ; }
  • 14. #include iostream.h void main ( ) { // an integer number int Num,i; // numebr of numbers int Num_Num; // total of numbers int Sum = 0; cout Enter the number of numbers : ; // get the number of numbers from user cin Num_Num; // loop from 1 to Num_Num. for (int Counter = 1; Counter = Num_Num ; i++ ) { cout Enter number ( Counter ) :; // get the number from user cin Num; // put the number in sum Sum += Num; } // end for // print the result cout The Result is : Sum ; } // end main
  • 15. #include iostream.h int Pluse ( int, int ); int Minus ( int, int ); int Div ( int, int ); int Mult ( int, int ); void main ( ) { int Fir_Num; int Sec_Num; char Ope; cout Enter the first number : ; cin Fir_Num; cout Enter the second number : ; cin Sec_Num; cout Enter ur operation : ; cin Ope; switch (Ope) { case ' + ' : cout The result is : ; break; case ' - ' : cout The result is : Minus ( Fir_Num, Sec_Num ); break; case '*' : cout The result is : Mult ( Fir_Num, Sec_Num ); case ' / ' : cout The result is : Div ( Fir_Num , Sec_Num ); break ; default : cout Sorry ur operation is wrong ; } } int Pluse ( int x, int y ) { return x + y ; } int Minus ( int x, int y ) { return x - y; } int Div ( int x, int y ) { if ( y == 0 ) { cout Error division by zero ; return 0; } else return x / y; } int Mult ( int x, int y ) { return x * y ; }
  • 16. #include iostream.h void main( ) { int Fir_Num; int Sec_Num; cout Enter the first number : ; cin Fir_Num ; cout Enter the second number : ; cin Sec_Num; cout The Result is : Fir_Num + Sec_Num ; }
  • 17. #include iostream.h void main ( ) { int Num_Of_Sub; int Grade; int Total = 0; int Average; cout Plz enter number of subjects : ; cin Num_Of_Sub; for (int Counter = 1; Counter = Num_Of_Sub; Counter++) { cout Enter grade number ( Counter ) : ; cin Grade; if (Grade = 50 Grade = 100) Total += Grade; else { cout Sorry ...grade is out of range !!!!! try againn; Counter--; } } Average = Total / Num_Of_Sub ; cout The average is : Average ; }
  • 18. #includeiostream.h void main() { long d1 , d2; char let; do{ coutenter the first numbern; cind1; coutenter the second numbern; cind2; cout the result of multiple two numbers is :n; coutd1*d2; coutn if you want to do again press any letter or number unless a n; cinlet; coutn; }while(let!='a'); } B y t h is y ou c a n (n u m *n u m ) a n d y ou a g a in a n y t im e in t e r (c h ,n u m )
  • 19. #includeiostream.h void main () { int k; cout enter your number : n ; cin k; if ( k50) cout the number is less than 50 ; else coutava darkatendl; } If and else
  • 20. #include iostream.h void main() { int z,y; cout Inter your longendl; cin z ; cout Inter friend's longendl; cin y; cout --------------------endl; if(zy) { cout You longerendl; cout Your long is zendl; coutendl; cout The average longs are ; cout (z+y)/2; } else { cout Your friend is longerendl; cout He's long is yendl; cout y*2 = y*2endl; cout y/2 = y/2; } }
  • 21. #includeiostream.h void main() { for(int i=1;i7;i++) { for(int j=1;j10;j++) { cout*; } coutn; } } ********** ********** ********** ********** ********** ********** ********** #includeiostream.h void main() { int sum; for(int i=1;i=8;i++) { for(int j=i;j=9;j++) { cout=; } sum+=j; coutn; } } ======== ======= ====== ===== ==== === == = + ++ +++ +++++ ++++++ +++++++ ++++++++
  • 22.
  • 23. #include iostream.h void main() { int x; cin x; switch (x) { case 1: cout welcomeendl; break; case 2: cout hello studentendl; break; case 3: cout introdaction to c++endl; break; default: cout bye bye; } }
  • 24. cout its a Saturnendl; break; case 7: cout its a URANUSendl; break; case 8: cout its a NEPTUNEendl; break; case 9: cout its a PLUTOendl; break; case 10: cout its a senda endl; break; default: cout err no plant to resemble this numberendl; break; } } #include iostream.h void main() { int x; cout inter number a planet endl; cin x; switch (x) { case 1: cout its a Mercuryendl; break; case 2: cout its a Venusendl; break; case 3: cout its a earthendl; break; case 4: cout its a Marsendl; break; case 5: cout its a Jupiterendl; break; case 6: About switch
  • 25. #includeiostream.h main() { int x; coutenter the decimal number:; cin x; while(x=12) {switch(x) { case 1: {coutIendl; coutenter the decimal number:;} break; case 2: {coutIIendl; coutenter the decimal number:;} break; case 3: {coutIIIendl; coutenter the decimal number:;} break; case 4: {coutIVendl; cout enter the decimal number:;} break; case 5: {coutVendl; coutenter the decimal number:;} break; case 6: {coutVIendl; coutenter the decimal number:;} case 8: {coutVIIIendl; coutenter the decimal number;} break; case 9: {coutIXendl; coutenter the decimal number;} break; case 10: {coutXIendl; coutenter the decimal number;} break; case 11: {coutXIIendl; coutenter the decimal number;} break; case 12: {coutXIIIendl; coutenter the decimal number:;} break; default: coutNOOOO; break; } cinx; } } break; case 7: {coutVIIendl; coutenter the decimal number:;} break;
  • 26. #include iostream.h void main() { int x, sum; sum = 0; do { cinx; sum+=x; }while (x!=0); coutsum of number is =sum; }
  • 27. #include iostream.h void main () { for (char x=65;x=90;x++) cout x; } a……..z #include iostream.h void main () { for (int x='A' ;x='Z' ;x++) cout x; } 65……..90 #include iostream.h void main () { float L, M; char ch; do { cout nEnter L: ; cin L; cout Enter M: ; cin M; cout nL+M= L+M; cout nL-M= L-M; cout nL*M= L*M; if (M != 0) cout nL/M= L/M; cout n Do Again (y/n): ; cin ch; } while (ch != 'n'); } Other more programming W hile for again
  • 28. #include iostream.h void main ( ) { for (int i = 0; i 15; i++) cout i * i ; } #include iostream.h void main () { int x = 10; cout x = x endl; cout n ++x = ++x endl; cout x++ = x++ endl; cout n x = x endl ; cout n --x = --x endl; cout x-- = x-- endl; cout n x = x endl ; } For information
  • 29. #include iostream.h #include math.h void main () { int x, y, P ; cout Enter a number: ; cin x ; cout Enter a power : ; cin y ; P = pow (x,y) ; cout The result is : P endl ; } #include iostream.h #include math.h void main ( ) { float num, ans; cout Enter a number: ; cin num; ans = sqrt(num) ; cout square root is: ans endl; } Calculus example
  • 30. #include iostream.h int sqr (int n) { int r; r=n*n; return r; } void main() { int k; cink; coutsqr(k)endl; } Function #include iostream.h int sqr (int); void main() { int k; cink; coutsqr(k)endl; } int sqr (int n) { int r; r=n*n; return r; }
  • 31. #include iostream.h void fun() { int i=10; coutiendl; } void main() { int i=5; fun(); coutiendl; } 10 5 #include iostream.h void azo() { int i=10; coutiendl; } void main() { int i=5; coutiendl; azo(); coutiendl; } 5 10 5 #include iostream.h void azo(int n) { n++; coutnendl; } void main() { int n=5; azo(n); coutnendl; } 6 5 #include iostream.h void main() { int x=100,y=5; int temp; temp=x; x=y; y=temp; coutxyendl; }
  • 32. #includeiostream.h int fact (int); void main () { int sum=0,i,n; cinn; for(i=0;i=n;i++) sum+=fact(i); coutsum = sum; } int fact (int n) { int i,s; s=1; for(i=n;i=1;i--) s*=i; return s; } 2—sum=4,3—sum=10 4—sum=34,5—sum=154 Sum = 1 + x^1 + x^2 + x^3 + x^4 + x^5 #includeiostream.h #includemath.h void main() { int sum=0,x,i; cinx; for(i=5;i=1;i--) sum+=pow(x,i); coutsum; }
  • 33. #include stdio.h void main ( ) { FILE * f; f=fopen(d:stdudent.txt,azad lesson); fprintf(f, welcome to C++); fclose(f); } file #includeiostream.h #includestdio.h #includestdlib.h void main() { FILE *out; int score; if((out=fopen(test.txt,w))==NULL) { coutcan not open filen; exit(-1); } coutenter a test score (0 terminate input); cinscore; while(score !=0) { fprintf(out,%dn,score); cout enter anather score; cinscore; } fclose(out); }