0% found this document useful (0 votes)
189 views

C++ Examples - Arabic

The document contains C++ programs to perform basic calculations and operations: 1. Programs to sum two numbers entered by the user or predefined. 2. A program to calculate the factorial of a given number. 3. Programs using loops, if/else statements, switch cases, and functions to perform operations like calculating powers, determining the largest of two numbers, and finding the length of an integer.

Uploaded by

anashata
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
189 views

C++ Examples - Arabic

The document contains C++ programs to perform basic calculations and operations: 1. Programs to sum two numbers entered by the user or predefined. 2. A program to calculate the factorial of a given number. 3. Programs using loops, if/else statements, switch cases, and functions to perform operations like calculating powers, determining the largest of two numbers, and finding the length of an integer.

Uploaded by

anashata
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

- .

c++

:
#include<iostream.h>
main()
{int x,y,z;
cout<<"please enter number one ";
cin>>x;
cout<<"please enter number tow ";
cin>>y;
z=x+y;
cout<<"the sum number : z= "<<z;
for(;;);
}

:
#include<iostream.h>
main()
{int x,y,z;
X=5;
Y=6;
z=x+y;
cout<<"the sum number : z= "<<z;
for(;;);
}

#include<iostream.h>
main()
{
int n,f;
cout<<" pls enter number ";
cin>>n;
f=1;
for(int i=1;i<=n;i++)
f=f*i ;
cout<<"factorial "<<n<<" : = ";
cout<<f;
for(;;);
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
1

- .

#include<iostream.h>
main()
{
int x=0;
cout<<"plze choose num1-7 ";

c++

case

cin>>x;
switch(x)
{
case 1:
cout<<"sat"<<endl;
break;
case 2:
cout<<"sun"<<endl;
break;
case 3:
cout<<"mon"<<endl;
break;
case 4:
cout<<"with"<<endl;
break;
case 5:
cout<<"thu"<<endl;
break;
case 6:
cout<<"tran"<<endl;
break;
case 7:
cout<<"fri"<<endl;
}
for(;;);
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
2

..... sun sat

- .

c++

#include <iostream.h>
main ()
{ int a;
cout<<"pleas enter number : ";
cin>>a;
cout<<a*1<<endl;
cout<<a*2<<endl;
cout<<a*3<<endl;
cout<<a*4<<endl;
cout<<a*5<<endl;
cout<<a*6<<endl;
cout<<a*7<<endl;
cout<<a*8<<endl;
cout<<a*9<<endl;
cout<<a*10<<endl;
for(;;);
}

#include <iostream.h>
main ()
{ int a;
cout<<"pleas enter number : ";
cin>>a;
for(int i =1;i<=10;i++)
cout<<a*i<<endl;
for(;;);
}

for X

:
#include<iostream.h>
main()
{int x,y,z;
cout<<"please enter number one ";
cin>>x;
cout<<"please enter number tow ";
cin>>y;
if (x>y)
cout<<"x as bigest";
else
if (x<y)
cout<<"y as bigest";
else
cout<<"ecuals";
for(;;);
}
programming in language c++ all student academic(2010-2011m)
By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
3

- .

c++

x,n x
#include<iostream.h>
main()
{
int n,y,x;
cout<<" pls enter number base\t";
cin>>n;
y=1;
cout<<" pls enter number power\t";
cin>>x;
for(int i=1;i<=n;i++)
y=y*x ;
cout<<"power(x,n)=> X^N = \t"<<y;
for(;;);
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
4

- .

c++

whil

:
#include<iostream.h>
main()
{
int n,f=1;
cout<<" pls enter number \t";
cin>>n;
while(n>0)
{
f=f*(n--);
}
cout<<"factorial number : f="<<f;
for(;;);
}

whil

(n--) *

:
#include<iostream.h>
main()
{
int n,f=0;
cout<<" pls enter number \t";
cin>>n;
while(n!=0)
{
n/=10;
f++;}
cout<<"toll number : f= "<<f;
for(;;);
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
5

c++

. -

do..while


. while .
:

: ...........................................................................
>#include<iostream.h
)(main
{
;int a=15,b=5,c
do
{
;c= a % b
;a= b
;b= c
}
;)while (c > 0
;cout<<a
;);;(for
}

)programming in language c++ all student academic(2010-2011m


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
6

- .

c++

: for

#include<iostream.h>
main()
{
int n=10,i,j;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
cout<<"*";
cout<<endl;
}
}

:for

#include<iostream.h>
main()
{
int n=10,i,j;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
cout<<"*";
cout<<endl;}
for(i=10;i>0;i--)
{
for(j=0;j<i;j++)
cout<<"*";
cout<<endl;
}
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
7

- .

c++

( )

#include<iostream.h>
main()
{
int n=20,i,j,m=n/2;
for(I = 0 ; I < n ; i++)
{
if (i < m )
for(j = 0 ; j < I ; j++)
cout<<"*";
else
{
for(j=m;j>0;j--)
cout<<"*";
m--;
}
cout<<endl;
}
}


#include<iostream.h>
main()
{
int n=10,i,j;
for( I = 0; i<n ;i++)
{
for( j=i; j < n; j++)
cout<<"*";
cout<<endl;
}
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
8

- .

c++

#include<iostream.h>
main()
{
int n=10,i,j;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
cout<<"*";
cout<<endl;}}

#include<iostream.h>
main()
{
int n=10,i,j;
for(i=1;i<10;i++)
{

for(j=1;j<i;j++)
cout<<"*";
cout<<endl;}
for(i=1;i<10;i++)
{
for(j=1;j<10;j++)
cout<<"*";
cout<<endl;
}
}
#include<iostream.h>
main()
{
int n=10,i,j;
for(i=1;i<10;i++)
{
for(j=1;j<i;j++)
cout<<"*";
cout<<endl;}
for(i=1;i<10;i++)
{
for(j=1;j<10;j++)
cout<<"*";
cout<<endl;
}
for(i=1;i<10;i++)
{
for(j=i;j<10;j++)
cout<<"*";
cout<<endl;}
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
9

- .

c++


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int n=10,i,j;
for(i=1;i<=100;i++)
if((i%2!=0)||(i%4!=0)||(i%6!=
0))
cout<<i<<endl;
getch();
}

for -

#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
main()
{
clrscr();
int s,n=10,i,j;
for(i=1;i<=5;i++)
{
s=1;
for(j=2;j<=i;j++)
s=s*j;
cout<<'!'<<setw(2)<<i<<setw(8)<<s<<endl;
}
getch();
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
10

- .

c++

switch do while n
one x=1
tow x=2
three x=3
#include<iostream.h>
#include<conio.h>
four x=4
#include<iomanip.h>
main()
{
clrscr();
int x=0;
cout<<"note:- "<<endl<<endl<<"for EXITE
enter value 100"<<endl;
do
{
cin>>x;
if(x>=1 && x<=5 && x!=100)
{ switch(x)
{
case 1: cout<<"one"<<endl;break;
case 2: cout<<"tow"<<endl;break;
case 3: cout<<"three"<<endl;break;
case 4: cout<<"four"<<endl;break;
case 5: cout<<"five"<<endl;break;
}
}
}
while(x!=100);
}

-
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int x;
cout<<"enter number:-";
cin>>x;
if(x>10 && x<=20)
cout<<"the value "<<x
<<"is between 10 -20 "<<endl;
getch();
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
11

- .

c++

while
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int n,s=1;
cout<<"enter number:-";
cin>>n;
while(n!=1)
{
s=s*n;
--n;
}
cout<<" fact number :" <<s;
getch();
}

do while

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
12

- .

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int i,j,n;
cout<<"pls enrer number n:";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
if(i+j<n+1)
cout<<"#" ;
else
cout<<"*";
cout<<endl;
}
getch();
}

c++


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int i,j,n;
cout<<"pls enrer number n:";
cin>>n;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
if(i+j<n+1)
cout<<"" ;
else
cout<<"*";
cout<<endl;
}
getch();
}

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
13

- .

c++

:
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int i,n,a=0,b=1,c;
cout<<" pls enter toaller sequnce : ";
cin>>n;
cout<<b;
for(i=0;i<n;i++)
{
c=b;
b=b+a;
a=c;
cout<<' '<<b;
}
getch();
}

X=1+1/2+1/3+1/4+.+1/N :

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
14

- .

c++

#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int i,n;
float s=0;
cout<<" pls enter toaller sequnce : ";
cin>>n;
for(i=1;i<=n;i++)
{
s=s+(1/i);
cout<<i<<" "<<s<<" ";}
getch();
}

:
-

programming in language c++ all student academic(2010-2011m)


By: T. wael qasem sutaih hodidah university college zabid
And college bagel . email:[email protected].
15

You might also like