10 template code program
Write a Program that does the following:-
- Promotes the user to enter 5 numbers.
- Print the Numbers.
- Print the sum and average of these five numbers.
#include<iostream.h>
void main()
{
int a,b,c,d,e,sum,avg;
cout<<"Enter the five numbers:";
cin>>a>>b>>c>>d>>e;
cout<<"the numbers you have entered are: ";
cout<<a<<" "<<b<<" ";
cout<<c<<" "<<d<<" "<<e<<endl;
sum = a + b + c + d + e;
avg = sum/5;
cout<<"the sum is "<<sum;
cout<<" and the average is "<<avg<<endl;
}
2
Write a Program that promotes the user to enter the length and
width of a rectangle and print its area.
#include <iostream.h>
void main()
{
double length,width;
cout<<"Enter the Length an the Width of the rectangle:";
cin>>length>>width;
cout<<"the area of the rectangle is "<<length*width<<endl;
}
3
Write a Program that finds the area of a circle.
#include <iostream.h>
void main()
{
const float PI = 3.14;
double r;
cout<<"Enter the Radius of the Circle:";
cin>>r;
cout<<"the area of the Circle is "<<PI*r*r<<endl;
}
4
Write a Program to find the absolute value of
an integer
#include <iostream.h>
void main()
{
int a;
cout<<"enter a number:";
cin>>a;
if(a<0)
a *= -1;
cout<<"the absolute value of the number is: "<<a<<endl;
}
5
Write a Program that reads two different integers
and print the largest
#include <iostream.h>
void main()
{
int a,b;
cout<<"enter two numbers:";
cin>>a>>b;
if(a>b)
cout<<a<<" is the largest"<<endl;
else
cout<<b<<" is the largest"<<endl;
}
6
Write a Program that reads operation with it's operands
and then print the result
#include <iostream.h>
void main()
{
double a,b;
char x;
cout<<"enter the operation:";
cin>>a>>x>>b;
if(x=='+')
cout<<a+b<<endl;
else if (x=='-')
cout<<a-b<<endl;
else if (x=='*')
cout<<a*b<<endl;
else if (x=='/')
cout<<a/b<<endl;
else
cout<<"Unknown operation"<<endl;
}
7
Write a Program to read a character if it's in alphabet then
find if it’s uppercase or lowercase. If it’s a digit print that it
is a digit.
Else print that it’s a special character.
#include <iostream.h>
void main()
{
char x;
cout<<"enter the char:";
cin>>x;
if(x>='A' && x<='Z')
cout<<x<<" is Uppercase char"<<endl;
else if(x>='a' && x<='z')
cout<<x<<" is Lowercase char"<<endl;
else if(x>='0' && x<='9')
cout<<x<<" is a Digit"<<endl;
else
cout<<x<<" is a special char"<<endl;
}
8
Write a loop to print the numbers from 1 to 10
#include <iostream.h>
void main()
{
int i = 0;
while(i<=10)
cout<<i++<<endl;
}
9
Write a Program to print the multiple of number 5
between 0 to 20
#include <iostream.h>
void main()
{
int i = 5;
while(i<=20)
{
cout<<i<<endl;
i+=5;
}
}
10
Write a loop to find the sum of numbers from 1 to 20
#include <iostream.h>
void main()
{
int sum=0,i = 0;
while(i<=20)
sum +=i++;
cout<<"the sum is: "<<sum<<endl;
}
11
Write a loop to find the sum of odd numbers from
20 to 300
#include <iostream.h>
void main()
{
int i = 20,sum = 0;
while(i<=300)
{
if(i%2==1)
sum += i;
i++;
}
cout<<"the sum is: "<<sum<<endl;
}
12
Find the sum of even number from 1 to 30
#include <iostream.h>
void main()
{
int i = 1,sum = 0;
while(i<=30)
{
if(i%2==0)
sum += i;
i++;
}
cout<<"the sum is: "<<sum<<endl;
}
13
Write a loop to find factorials for an entered number
#include <iostream.h>
void main()
{
int x,y;
cout<<"enter the number:";
cin>>x;
y=x;
while(x!=0)
{
if(y%x==0)
cout<<x<<endl;
x--;
}
}
14
Find the maximum between 20 numbers
#include <iostream.h>
void main()
{
int x,y;
cout<<"enter the number:";
cin>>x;
int i = 0;
while(i<=20)
{
if(x>y)
{
y =x;
cout<<"the Maximum until now is "<<y<<endl;
}
cin>>x;
i++;
}
} 15
Write a for loop to print number 1 to 40 each 5 on line
#include <iostream.h>
#include <iomanip.h>
void main()
{
for(int i=1;i<=40;i++)
{
cout<<setw(3)<<i;
if(i%5==0)
cout<<endl;
}
}
16
Write a Program that reads a number and perform the following
- print the number digits in reverse order.
- Find the sum of it's digits.
- Find the average of it's digits
#include<iostream>
#include<iomanip>
using namespace std;
void main()
{
int x,y,z=0,avg=0,sum=0;
cin>>x;
while(x!=0)
{
y = x%10;
x/=10;
cout<<y<<endl;
sum += y;
z++;
}
avg = sum/z;
cout<<"the sum is "<<sum<<endl;
cout<<"the avg is "<<avg<<endl;
} 17
Write a Program to read a set of non zero(when read zero, stop the program)
and find:
sum – average - maximum value - minimum value -
the number of values - sum of numbers that divide on 5
#include<iostream>
#include<iomanip>
using namespace std;
void main()
{
int x,y,max,min,z=0,avg=0,sum=0,sum5=0;
cin>>x;
max = x;
min = x;
while(x!=0)
{
if(x>max)
max = x;
if(x<min)
min =x; 18
19
sum+=x;
z++;
if(x%5==0)
sum5+=x;
cin>>x;
}
avg = sum/z;
cout<<"the sum is "<<sum<<endl;
cout<<"the average is "<<avg<<endl;
cout<<"the maximum value is "<<max<<endl;
cout<<"the minimum value is "<<min<<endl;
cout<<"the numbers of values is "<<z<<endl;
cout<<"the sum of numbers that divide on 5 is
"<<sum5<<endl;
}
Write a Loop that draws the following shape:
*
**
***
****
*****
#include<iostream.h>
void main()
{
for(int i = 0;i<5;i++)
{
for(int j = 0;j<=i;j++)
cout<<'*';
cout<<endl;
}
}
20
Write a Loop that draws the following shape
#include<iostream.h>
void main()
{
for(int i = 1;i<=3;i++)
{
for(int j =1;j<=3-i;j++)
cout<<' ';
for(int k = 1;k<=(2*i)-1;k++)
cout<<'*';
cout<<endl;
}
}
21
‫المدخل‬ ‫للعدد‬ ‫الصفر‬ ‫من‬ ‫الزوجية‬ ‫األعداد‬ ‫طباعة‬
#include <iostream.h>
int main()
{
int i,num;
cout<<"Enter the last number : ";
cin>>num;
for (i=0;i<=num;i++)
if (i%2==0)
cout<<i<<" ";
cout<<endl;
return 0;
}
22
‫المدخل‬ ‫للعدد‬ ‫الصفر‬ ‫من‬ ‫الفردية‬ ‫األعداد‬ ‫طباعة‬:
#include <iostream.h>
int main()
{
int i,num;
cout<<"Enter the last number : ";
cin>>num;
for (i=0;i<=num;i++)
if (i%2!=0)
cout<<i<<" ";
cout<<endl;
return 0;
}
23
‫العدد‬ ‫ذلك‬ ‫هو‬ ‫ويختبر‬ ‫عدد‬ ‫أي‬ ‫بإدخال‬ ‫أنت‬ ‫تقوم‬ ‫برنامج‬
‫صفر‬ ‫أو‬ ‫سالب‬ ‫أو‬ ‫موجب‬ ‫أنه‬ ‫حيث‬ ‫من‬..
#include <iostream.h>
int main()
{
float num;
cout<<"Enter the number : ";
cin>>num;
if(num>0)
cout<<num <<" is Positive Number"<<endl;
else if(num<0)
cout<<num <<" is Negative Number"<<endl;
else
cout<<num<<" is Zero"<<endl;
return 0;
}
24
‫برنامج‬‫ويقوم‬ ‫أرقام‬ ‫عشرة‬ ‫بإدخال‬ ‫خالله‬ ‫من‬ ‫تقوم‬
‫بينهم‬ ‫عدد‬ ‫وأصغر‬ ‫أكبر‬ ‫بإيجاد‬ ‫هو‬:
#include<iostream.h>
int main()
{
float num,max=0,min=3200;
cout<<"Enter 10 numbers : ";
for(int i=0;i<10;i++)
{
cin>>num;
if(max<num)
max=num;
if(min>num)
min=num;
}
cout<<"The Maximum Numbers is : "<<max<<endl;
cout<<"The Minimum Numbers is : "<<min<<endl;
return 0;
}
25
‫منهما‬ ‫األكبر‬ ‫ويوجد‬ ‫عددين‬ ‫بإدخال‬ ‫تقوم‬:‫أخرى‬ ‫بطريقة‬:
#include<iostream.h>
int main()
{
float num1,num2,max;
cout<<"Enter num1 : ";
cin>>num1;
cout<<"Enter num2 : ";
cin>>num2;
max=(num1>=num2)?num1:num2;
cout<<"The Maximum Numbers is : "<<max<<endl;
return 0;
}
26
‫بينهما‬ ‫األصغر‬ ‫ويوجد‬ ‫عددين‬ ‫بإدخال‬ ‫تقوم‬:
#include<iostream.h>
int main()
{
float num1,num2,min;
cout<<"Enter num1 : ";
cin>>num1;
cout<<"Enter num2 : ";
cin>>num2;
min=(num1<=num2)?num1:num2;
cout<<"The Minimum Numbers is : "<<min<<endl;
return 0;
}
27
‫يقوم‬ ‫ثم‬ ‫الباسوورد‬ ‫إدخال‬ ‫المستخدم‬ ‫من‬ ‫يطلب‬ ‫برنامج‬
‫باختباره‬..
#include<iostream.h>
#include<string.h>
int main()
{
const char a[6]="admin";
char pass[6];
cout<<"Enter Your Password : ";
cin>>pass;
if(strcmp(pass,a)==0)
cout<<"Welcom to my Program.."<<endl;
else
cout<<"You are Not Allowed to Access This Program"<<endl;
return 0;
}
28
‫المضروب‬
include <iostream.h>#
int main()
{
int num,fact=1;
cout<<"Enter The Number: ";
cin>>num;
for(int i=2;i<=num;i++)
fact*=i;//fact=fact*i
cout<<"Factorial = "<<fact<<endl;
return 0;
}
29
‫باستخدام‬ ‫المضروب‬while:
#include <iostream.h>
int main()
{
int i=1,num,fact=1;
cout<<"Enter The Number: ";
cin>>num;
while(i<=num)
{
fact*=i;//fact=fact*i
i++;
}
cout<<"Factorial = "<<fact<<endl;
return 0;
}
30
‫األعداد‬ ‫من‬ ‫مجموعة‬ ‫إدخال‬ ‫المستخدم‬ ‫من‬ ‫يطلب‬ ‫برنامج‬
‫لهذه‬ ‫المتوسط‬ ‫بحساب‬ ‫يقوم‬ ‫ثم‬ ‫بالصفر‬ ‫تنتهي‬
‫يتجاهله‬ ‫فإنه‬ ‫سالب‬ ‫عدد‬ ‫صادف‬ ‫وإذا‬ ‫األعداد‬
‫باستخدام‬ ‫الحسبان‬ ‫في‬ ‫واليضعه‬Continue‫ثم‬
‫العملية‬ ‫يكمل‬
#include<iostream.h>
int main()
{
int x,sum=0,count=0;
cout<<"Enter the numbers : "<<endl;
for (;;)
{
cin>>x;
count+=1;
if (x<0)
{
count-=1;
continue;
}
else
sum=sum+x;
31
32
if(x==0)
{
count-=1;
break;
}
}
cout<<"The Avarege = "<<sum/count<<endl;
return 0;
}
‫طريق‬ ‫عن‬ ‫المستطيل‬ ‫مساحة‬ ‫بحساب‬ ‫يقوم‬ ‫برنامج‬
‫بالحساب‬ ‫يقوم‬ ‫آخر‬ ‫بروسيجر‬ ‫استدعاء‬..
#include<iostream.h>
float cal(float length,float width);
void main()
{
float length,width,area;
cout<<"Enter the rectangle length:";
cin>>length;
cout<<"Enter the rectangle width:";
cin>>width;
area=cal(length,width);
cout<<"Rectangle Area = "<<area<<endl;
}
float cal(float length,float width)
{
float w;
w = length * width;
return w;
}
33
‫بطباعة‬ ‫هو‬ ‫يقوم‬ ‫ثم‬ ‫أسمك‬ ‫بإدخال‬ ‫انت‬ ‫تقوم‬ ‫برنامج‬
‫ادخلته‬ ‫الذي‬ ‫اسمك‬ ‫فيه‬ ‫يظهر‬ ‫ترحيبيه‬ ‫عبارة‬.
#include <iostream>
#include <string>
using namespace std;
int main()
{
string name;
cout<<"Enter your name: ";
cin>>name;
cout<<"Hello "<<name<<endl;
return 0;
}
34

More Related Content

PDF
C++ TUTORIAL 1
PDF
C++ TUTORIAL 2
DOCX
Programa en C++ ( escriba 3 números y diga cual es el mayor))
PDF
C++ TUTORIAL 5
PDF
54602399 c-examples-51-to-108-programe-ee01083101
PDF
C++ TUTORIAL 3
PDF
C++ TUTORIAL 9
PDF
C++ TUTORIAL 4
C++ TUTORIAL 1
C++ TUTORIAL 2
Programa en C++ ( escriba 3 números y diga cual es el mayor))
C++ TUTORIAL 5
54602399 c-examples-51-to-108-programe-ee01083101
C++ TUTORIAL 3
C++ TUTORIAL 9
C++ TUTORIAL 4

What's hot (20)

PDF
C++ TUTORIAL 10
DOCX
Cs project
PDF
C++ TUTORIAL 6
PDF
C++ TUTORIAL 7
PDF
C++ Programming - 1st Study
DOCX
C++ file
PDF
C++ Programming - 2nd Study
PPTX
C- Programs - Harsh
DOCX
SaraPIC
DOCX
Basic Programs of C++
DOCX
Best C Programming Solution
PDF
String
DOCX
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
PDF
C++ Programming - 4th Study
DOCX
Oops practical file
PDF
C++ L03-Control Structure
PDF
Stl algorithm-Basic types
PDF
C++ Programming - 3rd Study
TXT
c++ program for Railway reservation
PDF
C++ L05-Functions
C++ TUTORIAL 10
Cs project
C++ TUTORIAL 6
C++ TUTORIAL 7
C++ Programming - 1st Study
C++ file
C++ Programming - 2nd Study
C- Programs - Harsh
SaraPIC
Basic Programs of C++
Best C Programming Solution
String
COMPUTER SCIENCE CLASS 12 PRACTICAL FILE
C++ Programming - 4th Study
Oops practical file
C++ L03-Control Structure
Stl algorithm-Basic types
C++ Programming - 3rd Study
c++ program for Railway reservation
C++ L05-Functions

Viewers also liked (19)

PPTX
Present simple.silvia viloria
PPTX
Core marketing concepts
PDF
الشرقية قيكس سنة من الإنجازات
PDF
CancerRegistry PosterFINAL 091208
PPTX
González uscanga keila samantha dhtic19 tarea5
PPTX
Tecnicas ventas hurtado
PDF
Harappa e Mohenjo Daro
PDF
Wc Prima 4X4 par Allia salle de bains
PDF
Renato Rinaldi e Andrea Collavino, Memoria di massa
PDF
Web e social network nella PA: #culturavivafvg, raccontare il patrimonio cult...
PPT
تجربتي مع مجموعة عقال
PDF
Lavoro autonomo abituale
PDF
Il concetto di guerra dall'antichità al medioevo
PDF
N 20141112 una obra digna - fuente mayucu (x)
DOCX
Base de datos access 2010
PPT
Holding di Famiglia e Passaggio Generazionale
PDF
ملخص تقنية تصميم صفحات الويب - الوحدة الخامسة
PPSX
Análisis de Mercado - Caso Iberia
PPT
Ch1 defining marketing for the 21st century abendan
Present simple.silvia viloria
Core marketing concepts
الشرقية قيكس سنة من الإنجازات
CancerRegistry PosterFINAL 091208
González uscanga keila samantha dhtic19 tarea5
Tecnicas ventas hurtado
Harappa e Mohenjo Daro
Wc Prima 4X4 par Allia salle de bains
Renato Rinaldi e Andrea Collavino, Memoria di massa
Web e social network nella PA: #culturavivafvg, raccontare il patrimonio cult...
تجربتي مع مجموعة عقال
Lavoro autonomo abituale
Il concetto di guerra dall'antichità al medioevo
N 20141112 una obra digna - fuente mayucu (x)
Base de datos access 2010
Holding di Famiglia e Passaggio Generazionale
ملخص تقنية تصميم صفحات الويب - الوحدة الخامسة
Análisis de Mercado - Caso Iberia
Ch1 defining marketing for the 21st century abendan

Similar to 10 template code program (20)

PPT
PPTX
Example Programs of CPP programs ch 1.pptx
PDF
Please help. C++ The program is an interactive program th.pdf
PDF
Higher Secondary (Affiliated State Board) Computer Commerce Lab Programmes
PDF
You will be implementing the following functions. You may modify the.pdf
PDF
CBSE Question Paper Computer Science with C++ 2011
PDF
Common problems solving using c
DOCX
Cs pritical file
DOCX
Computer Practical XII
PDF
C++ Nested loops, matrix and fuctions.pdf
PDF
C++ practical
PDF
computer science sample papers 2
DOCX
Practical File of c++.docx lab manual program question
PDF
Introduction to Basic C++ Program Examples .pdf
PDF
Programming Fundamentals presentation slide
DOCX
Bijender (1)
PDF
Object Oriented Programming Using C++ Practical File
PDF
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
PDF
Please use the code below and make it operate as one program- Notating.pdf
PPTX
Computational Physics Cpp Portiiion.pptx
Example Programs of CPP programs ch 1.pptx
Please help. C++ The program is an interactive program th.pdf
Higher Secondary (Affiliated State Board) Computer Commerce Lab Programmes
You will be implementing the following functions. You may modify the.pdf
CBSE Question Paper Computer Science with C++ 2011
Common problems solving using c
Cs pritical file
Computer Practical XII
C++ Nested loops, matrix and fuctions.pdf
C++ practical
computer science sample papers 2
Practical File of c++.docx lab manual program question
Introduction to Basic C++ Program Examples .pdf
Programming Fundamentals presentation slide
Bijender (1)
Object Oriented Programming Using C++ Practical File
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
Please use the code below and make it operate as one program- Notating.pdf
Computational Physics Cpp Portiiion.pptx

More from Bint EL-maghrabi (9)

PDF
9 message error
PDF
8 header files
PDF
7 functions
PDF
PDF
4 flow control statements
PDF
3 operators
PDF
2 variables and constants
PDF
PDF
01 Introduction in C++
9 message error
8 header files
7 functions
4 flow control statements
3 operators
2 variables and constants
01 Introduction in C++

Recently uploaded (20)

PDF
Design and Evaluation of a Inonotus obliquus-AgNP-Maltodextrin Delivery Syste...
PPSX
namma_kalvi_12th_botany_chapter_9_ppt.ppsx
PDF
IS1343_2012...........................pdf
PDF
V02-Session-4-Leadership-Through-Assessment-MLB.pdf
PPT
hsl powerpoint resource goyloveh feb 07.ppt
PDF
GIÁO ÁN TIẾNG ANH 7 GLOBAL SUCCESS (CẢ NĂM) THEO CÔNG VĂN 5512 (2 CỘT) NĂM HỌ...
PPTX
FILIPINO 8 Q2 WEEK 1(DAY 1).power point presentation
PPTX
ENGlishGrade8_Quarter2_WEEK1_LESSON1.pptx
PDF
Unleashing the Potential of the Cultural and creative industries
PDF
3-Elementary-Education-Prototype-Syllabi-Compendium.pdf
PDF
Jana-Ojana Finals 2025 - School Quiz by Pragya - UEMK Quiz Club
PDF
New_Round_Up_6_SB.pdf download for free, easy to learn
PPTX
GW4 BioMed Candidate Support Webinar 2025
PPTX
Approach to a child with acute kidney injury
PPTX
MMW-CHAPTER-1-final.pptx major Elementary Education
PPTX
Environmental Sciences and Sustainability Chapter 2
PDF
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
PDF
Global strategy and action plan on oral health 2023 - 2030.pdf
PDF
horaris de grups del curs 2025-2026 de l'institut
PDF
Teacher's Day Quiz 2025
Design and Evaluation of a Inonotus obliquus-AgNP-Maltodextrin Delivery Syste...
namma_kalvi_12th_botany_chapter_9_ppt.ppsx
IS1343_2012...........................pdf
V02-Session-4-Leadership-Through-Assessment-MLB.pdf
hsl powerpoint resource goyloveh feb 07.ppt
GIÁO ÁN TIẾNG ANH 7 GLOBAL SUCCESS (CẢ NĂM) THEO CÔNG VĂN 5512 (2 CỘT) NĂM HỌ...
FILIPINO 8 Q2 WEEK 1(DAY 1).power point presentation
ENGlishGrade8_Quarter2_WEEK1_LESSON1.pptx
Unleashing the Potential of the Cultural and creative industries
3-Elementary-Education-Prototype-Syllabi-Compendium.pdf
Jana-Ojana Finals 2025 - School Quiz by Pragya - UEMK Quiz Club
New_Round_Up_6_SB.pdf download for free, easy to learn
GW4 BioMed Candidate Support Webinar 2025
Approach to a child with acute kidney injury
MMW-CHAPTER-1-final.pptx major Elementary Education
Environmental Sciences and Sustainability Chapter 2
NGÂN HÀNG CÂU HỎI TÁCH CHỌN LỌC THEO CHUYÊN ĐỀ TỪ ĐỀ THI THỬ TN THPT 2025 TIẾ...
Global strategy and action plan on oral health 2023 - 2030.pdf
horaris de grups del curs 2025-2026 de l'institut
Teacher's Day Quiz 2025

10 template code program

  • 2. Write a Program that does the following:- - Promotes the user to enter 5 numbers. - Print the Numbers. - Print the sum and average of these five numbers. #include<iostream.h> void main() { int a,b,c,d,e,sum,avg; cout<<"Enter the five numbers:"; cin>>a>>b>>c>>d>>e; cout<<"the numbers you have entered are: "; cout<<a<<" "<<b<<" "; cout<<c<<" "<<d<<" "<<e<<endl; sum = a + b + c + d + e; avg = sum/5; cout<<"the sum is "<<sum; cout<<" and the average is "<<avg<<endl; } 2
  • 3. Write a Program that promotes the user to enter the length and width of a rectangle and print its area. #include <iostream.h> void main() { double length,width; cout<<"Enter the Length an the Width of the rectangle:"; cin>>length>>width; cout<<"the area of the rectangle is "<<length*width<<endl; } 3
  • 4. Write a Program that finds the area of a circle. #include <iostream.h> void main() { const float PI = 3.14; double r; cout<<"Enter the Radius of the Circle:"; cin>>r; cout<<"the area of the Circle is "<<PI*r*r<<endl; } 4
  • 5. Write a Program to find the absolute value of an integer #include <iostream.h> void main() { int a; cout<<"enter a number:"; cin>>a; if(a<0) a *= -1; cout<<"the absolute value of the number is: "<<a<<endl; } 5
  • 6. Write a Program that reads two different integers and print the largest #include <iostream.h> void main() { int a,b; cout<<"enter two numbers:"; cin>>a>>b; if(a>b) cout<<a<<" is the largest"<<endl; else cout<<b<<" is the largest"<<endl; } 6
  • 7. Write a Program that reads operation with it's operands and then print the result #include <iostream.h> void main() { double a,b; char x; cout<<"enter the operation:"; cin>>a>>x>>b; if(x=='+') cout<<a+b<<endl; else if (x=='-') cout<<a-b<<endl; else if (x=='*') cout<<a*b<<endl; else if (x=='/') cout<<a/b<<endl; else cout<<"Unknown operation"<<endl; } 7
  • 8. Write a Program to read a character if it's in alphabet then find if it’s uppercase or lowercase. If it’s a digit print that it is a digit. Else print that it’s a special character. #include <iostream.h> void main() { char x; cout<<"enter the char:"; cin>>x; if(x>='A' && x<='Z') cout<<x<<" is Uppercase char"<<endl; else if(x>='a' && x<='z') cout<<x<<" is Lowercase char"<<endl; else if(x>='0' && x<='9') cout<<x<<" is a Digit"<<endl; else cout<<x<<" is a special char"<<endl; } 8
  • 9. Write a loop to print the numbers from 1 to 10 #include <iostream.h> void main() { int i = 0; while(i<=10) cout<<i++<<endl; } 9
  • 10. Write a Program to print the multiple of number 5 between 0 to 20 #include <iostream.h> void main() { int i = 5; while(i<=20) { cout<<i<<endl; i+=5; } } 10
  • 11. Write a loop to find the sum of numbers from 1 to 20 #include <iostream.h> void main() { int sum=0,i = 0; while(i<=20) sum +=i++; cout<<"the sum is: "<<sum<<endl; } 11
  • 12. Write a loop to find the sum of odd numbers from 20 to 300 #include <iostream.h> void main() { int i = 20,sum = 0; while(i<=300) { if(i%2==1) sum += i; i++; } cout<<"the sum is: "<<sum<<endl; } 12
  • 13. Find the sum of even number from 1 to 30 #include <iostream.h> void main() { int i = 1,sum = 0; while(i<=30) { if(i%2==0) sum += i; i++; } cout<<"the sum is: "<<sum<<endl; } 13
  • 14. Write a loop to find factorials for an entered number #include <iostream.h> void main() { int x,y; cout<<"enter the number:"; cin>>x; y=x; while(x!=0) { if(y%x==0) cout<<x<<endl; x--; } } 14
  • 15. Find the maximum between 20 numbers #include <iostream.h> void main() { int x,y; cout<<"enter the number:"; cin>>x; int i = 0; while(i<=20) { if(x>y) { y =x; cout<<"the Maximum until now is "<<y<<endl; } cin>>x; i++; } } 15
  • 16. Write a for loop to print number 1 to 40 each 5 on line #include <iostream.h> #include <iomanip.h> void main() { for(int i=1;i<=40;i++) { cout<<setw(3)<<i; if(i%5==0) cout<<endl; } } 16
  • 17. Write a Program that reads a number and perform the following - print the number digits in reverse order. - Find the sum of it's digits. - Find the average of it's digits #include<iostream> #include<iomanip> using namespace std; void main() { int x,y,z=0,avg=0,sum=0; cin>>x; while(x!=0) { y = x%10; x/=10; cout<<y<<endl; sum += y; z++; } avg = sum/z; cout<<"the sum is "<<sum<<endl; cout<<"the avg is "<<avg<<endl; } 17
  • 18. Write a Program to read a set of non zero(when read zero, stop the program) and find: sum – average - maximum value - minimum value - the number of values - sum of numbers that divide on 5 #include<iostream> #include<iomanip> using namespace std; void main() { int x,y,max,min,z=0,avg=0,sum=0,sum5=0; cin>>x; max = x; min = x; while(x!=0) { if(x>max) max = x; if(x<min) min =x; 18
  • 19. 19 sum+=x; z++; if(x%5==0) sum5+=x; cin>>x; } avg = sum/z; cout<<"the sum is "<<sum<<endl; cout<<"the average is "<<avg<<endl; cout<<"the maximum value is "<<max<<endl; cout<<"the minimum value is "<<min<<endl; cout<<"the numbers of values is "<<z<<endl; cout<<"the sum of numbers that divide on 5 is "<<sum5<<endl; }
  • 20. Write a Loop that draws the following shape: * ** *** **** ***** #include<iostream.h> void main() { for(int i = 0;i<5;i++) { for(int j = 0;j<=i;j++) cout<<'*'; cout<<endl; } } 20
  • 21. Write a Loop that draws the following shape #include<iostream.h> void main() { for(int i = 1;i<=3;i++) { for(int j =1;j<=3-i;j++) cout<<' '; for(int k = 1;k<=(2*i)-1;k++) cout<<'*'; cout<<endl; } } 21
  • 22. ‫المدخل‬ ‫للعدد‬ ‫الصفر‬ ‫من‬ ‫الزوجية‬ ‫األعداد‬ ‫طباعة‬ #include <iostream.h> int main() { int i,num; cout<<"Enter the last number : "; cin>>num; for (i=0;i<=num;i++) if (i%2==0) cout<<i<<" "; cout<<endl; return 0; } 22
  • 23. ‫المدخل‬ ‫للعدد‬ ‫الصفر‬ ‫من‬ ‫الفردية‬ ‫األعداد‬ ‫طباعة‬: #include <iostream.h> int main() { int i,num; cout<<"Enter the last number : "; cin>>num; for (i=0;i<=num;i++) if (i%2!=0) cout<<i<<" "; cout<<endl; return 0; } 23
  • 24. ‫العدد‬ ‫ذلك‬ ‫هو‬ ‫ويختبر‬ ‫عدد‬ ‫أي‬ ‫بإدخال‬ ‫أنت‬ ‫تقوم‬ ‫برنامج‬ ‫صفر‬ ‫أو‬ ‫سالب‬ ‫أو‬ ‫موجب‬ ‫أنه‬ ‫حيث‬ ‫من‬.. #include <iostream.h> int main() { float num; cout<<"Enter the number : "; cin>>num; if(num>0) cout<<num <<" is Positive Number"<<endl; else if(num<0) cout<<num <<" is Negative Number"<<endl; else cout<<num<<" is Zero"<<endl; return 0; } 24
  • 25. ‫برنامج‬‫ويقوم‬ ‫أرقام‬ ‫عشرة‬ ‫بإدخال‬ ‫خالله‬ ‫من‬ ‫تقوم‬ ‫بينهم‬ ‫عدد‬ ‫وأصغر‬ ‫أكبر‬ ‫بإيجاد‬ ‫هو‬: #include<iostream.h> int main() { float num,max=0,min=3200; cout<<"Enter 10 numbers : "; for(int i=0;i<10;i++) { cin>>num; if(max<num) max=num; if(min>num) min=num; } cout<<"The Maximum Numbers is : "<<max<<endl; cout<<"The Minimum Numbers is : "<<min<<endl; return 0; } 25
  • 26. ‫منهما‬ ‫األكبر‬ ‫ويوجد‬ ‫عددين‬ ‫بإدخال‬ ‫تقوم‬:‫أخرى‬ ‫بطريقة‬: #include<iostream.h> int main() { float num1,num2,max; cout<<"Enter num1 : "; cin>>num1; cout<<"Enter num2 : "; cin>>num2; max=(num1>=num2)?num1:num2; cout<<"The Maximum Numbers is : "<<max<<endl; return 0; } 26
  • 27. ‫بينهما‬ ‫األصغر‬ ‫ويوجد‬ ‫عددين‬ ‫بإدخال‬ ‫تقوم‬: #include<iostream.h> int main() { float num1,num2,min; cout<<"Enter num1 : "; cin>>num1; cout<<"Enter num2 : "; cin>>num2; min=(num1<=num2)?num1:num2; cout<<"The Minimum Numbers is : "<<min<<endl; return 0; } 27
  • 28. ‫يقوم‬ ‫ثم‬ ‫الباسوورد‬ ‫إدخال‬ ‫المستخدم‬ ‫من‬ ‫يطلب‬ ‫برنامج‬ ‫باختباره‬.. #include<iostream.h> #include<string.h> int main() { const char a[6]="admin"; char pass[6]; cout<<"Enter Your Password : "; cin>>pass; if(strcmp(pass,a)==0) cout<<"Welcom to my Program.."<<endl; else cout<<"You are Not Allowed to Access This Program"<<endl; return 0; } 28
  • 29. ‫المضروب‬ include <iostream.h># int main() { int num,fact=1; cout<<"Enter The Number: "; cin>>num; for(int i=2;i<=num;i++) fact*=i;//fact=fact*i cout<<"Factorial = "<<fact<<endl; return 0; } 29
  • 30. ‫باستخدام‬ ‫المضروب‬while: #include <iostream.h> int main() { int i=1,num,fact=1; cout<<"Enter The Number: "; cin>>num; while(i<=num) { fact*=i;//fact=fact*i i++; } cout<<"Factorial = "<<fact<<endl; return 0; } 30
  • 31. ‫األعداد‬ ‫من‬ ‫مجموعة‬ ‫إدخال‬ ‫المستخدم‬ ‫من‬ ‫يطلب‬ ‫برنامج‬ ‫لهذه‬ ‫المتوسط‬ ‫بحساب‬ ‫يقوم‬ ‫ثم‬ ‫بالصفر‬ ‫تنتهي‬ ‫يتجاهله‬ ‫فإنه‬ ‫سالب‬ ‫عدد‬ ‫صادف‬ ‫وإذا‬ ‫األعداد‬ ‫باستخدام‬ ‫الحسبان‬ ‫في‬ ‫واليضعه‬Continue‫ثم‬ ‫العملية‬ ‫يكمل‬ #include<iostream.h> int main() { int x,sum=0,count=0; cout<<"Enter the numbers : "<<endl; for (;;) { cin>>x; count+=1; if (x<0) { count-=1; continue; } else sum=sum+x; 31
  • 33. ‫طريق‬ ‫عن‬ ‫المستطيل‬ ‫مساحة‬ ‫بحساب‬ ‫يقوم‬ ‫برنامج‬ ‫بالحساب‬ ‫يقوم‬ ‫آخر‬ ‫بروسيجر‬ ‫استدعاء‬.. #include<iostream.h> float cal(float length,float width); void main() { float length,width,area; cout<<"Enter the rectangle length:"; cin>>length; cout<<"Enter the rectangle width:"; cin>>width; area=cal(length,width); cout<<"Rectangle Area = "<<area<<endl; } float cal(float length,float width) { float w; w = length * width; return w; } 33
  • 34. ‫بطباعة‬ ‫هو‬ ‫يقوم‬ ‫ثم‬ ‫أسمك‬ ‫بإدخال‬ ‫انت‬ ‫تقوم‬ ‫برنامج‬ ‫ادخلته‬ ‫الذي‬ ‫اسمك‬ ‫فيه‬ ‫يظهر‬ ‫ترحيبيه‬ ‫عبارة‬. #include <iostream> #include <string> using namespace std; int main() { string name; cout<<"Enter your name: "; cin>>name; cout<<"Hello "<<name<<endl; return 0; } 34