c++ programming codes idea, Summaries of C programming

you will find every thing you need for c++ programming codes idea

Typology: Summaries

2020/2021

Uploaded on 06/30/2023

aya-ah
aya-ah 🇮🇶

1 document

1 / 39

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Examples
: First Elements of C++.
: Selection Statements.
: Iteration Statements .
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27

Partial preview of the text

Download c++ programming codes idea and more Summaries C programming in PDF only on Docsity!

Examples

: First Elements of C++.

: Selection Statements.

: Iteration Statements.

The If/else Statement Structure:

.. Loop Statements:

The loop statements are essential to construct systematic

block styled

programming. C++ provides three iteration structures: while,

do/while, and for.

1. While Repetition Structure:

2. Do / While Statement:

EX 1

#include using namespace std; int main() { cout<<"Computer Science"; return 0; } // Computer Science كلمة طبع هو االخراج EX 2 <----------------------------------------------------------------------> // رقمين لجمع برنامج #include using namespace std; int main() { int a,b; cout<<"enter the value of a "; cin>>a; cout<<"enter the value of b "; cin>>b; cout<<"a+b = "<<a+b; return 0; } // الجمع ناتج ويعطي ندخلها قيمتين جمع عن عبارة هو البرنامج اخراج // كل نضيف انه ممكن او ضرب او قسمة او طرح الى العملية نبدل ممكن امع السابقة العمليات EX 3 <----------------------------------------------------------------------> // 40 ال الى 1 من االعداد لطبع برنامج #include using namespace std; int main() { int i; for(i=1;i<=40;i++) cout<<" "<<i; return 0; } // الى وتستمر 2 و 1 رقم من تبدأ ارقام سلسلة عن عبارة يكون البرنامج اخراج 40 الرقم // ومقدار 40 يساوي او اصغر والشرط 1 كانت االبتدائية القيمة النه السبب فقط 1 هو الزيادة

EX 4

#include using namespace std; int main() { int i; for(i=5;i<=35;i=i+5) cout<<" ,"<<i; return 0; } /* ,5, 10, 15, 20, 25, 30, 35 كاالتي يكون البرنامج اخراج ايضا 5 هو معلوم الزيادة وومقدار 5 برقم تبدأ سلسلة بالسؤال طلب انه بما 35 ب وتنتهي ومقدار 35 ويساي اصغر والشرط 5 البدائية القيمةهو الفور باستخدام الحل قيمة نطبع ثم 5 الزيادة كماموضح الفارزة مع i / EX 5 <----------------------------------------------------------------------> // كاالتي موضحة كما معينة سلسلة لطبع برنامج // 3,-6,9,-12,15,-18,21,-24, #include using namespace std; int main() { int i; for(i=3;i<=24;i=i+3) if(i%2==0) cout<<i-1<<","; else cout<<i<<","; return 0; } // 3,-6,9,-12,15,-18,21,-24, كاالتي يكون البرنامج اخراج // ومقدار 24 بالرقموتنتهي 3 برقم تبدأ سلسلة طباعة يطلب البرنامج 3 الزيادة // هو الزوجي الرقم اهذ وبالسلسله موجب الرقم ومرة سالب الرقم مرة لكن سالبة بقيمة مضروب يعني سالب // الزوجية لالرقام الفور عبارة بعد شرط نعمل // مطلوب كما الفارزة مع واحد سالب في مضروبةاآلي قيمة الطبع فيكون بالسؤال // الى تلقائيا فيذهب الزوجي الرقم يجد لم واذا سيطبع القيمة وجد فأذا ايلس عبارة بسبب الفردي الرقم // اشارة بدون الفارزة مع اآلي قيمة فقط الثانية الطبع عبارة النه

EX 8

//Write a program that reads the radius of a circle, then computes and //outputs its area. #include using namespace std; main( ) { float pi = 3.14; int r; float c; cout<< "enter the radius of circle:"; cin>>r; cout<<endl; c = r * r * pi; cout << "the area of circle:"<< c; return 0; } // الدائرة مساحة يحسب يريد هو شائع مثال // 5 رقم دخلنا مثال القطر نصف قيمة ندخلة انه منة فالمطلوب // كاالتي يكون البرنامج اخراج // enter the radius of circle: 5 //the area of circle: 78. // اعتبرناها سي وقيمة للباي قيمة وعرفنا استخدمنا رياضيةعملية مجرد اآلر وقيمة المساحة // الثابتة النسبة في تربيع القطر نصف هو الدائرة مساحة وقانونالقطر نصف // سي المساحة فرضنا الي المتغير قيمة مع توضيحية عبارة تكون الطباعة EX 9 <----------------------------------------------------------------------> // write a program and find sum this series // s = 1/3 + 1/6 + 1/9 + 1/12 + 1/15 + 1/18 +...+ 1/27 + 1/ #include using namespace std; int main() { float i,sum=0; for(i=3;i<=30;i=i+3) sum=sum+(1/i); cout<<"the sum is "<<sum; return 0; } // السلسلة جمع ناتج البرنامج اخراج //OUTPUT 0.

EX 10

// write a program and find sum this series // s = 1/35 + 1/30 + 1/25 + 1/20 + 1/15 + 1/10 + 1/ #include using namespace std; int main() { float i,sum=0; for(i=35;i>=5;i=i-5) sum=sum+(1/i); cout<<"The sum is "<<sum; return 0; } //output is //The sum is 0. EX 11 <----------------------------------------------------------------------> // write a program and find sum this series // s = 1/4 + 1/8 + 1/12 + 1/16 + 1/20 + 1/n #include using namespace std; int main() { float i,sum=0; int n; cout<<"enter the number "<<endl; cin>>n; for(i=4;i<=n;i=i+4) sum=sum+(1/i); cout<<"The sum is "<<sum; return 0; } //output is //enter the number 24 //The sum is 0. EX 12 <----------------------------------------------------------------------> // write a program and find sum this series // s = 1/45 + 1/36 + 1/27 + 1/18 + 1/ #include using namespace std; int main() { float i,sum=0; for(i=45;i>=9;i=i-9) sum=sum+(1/i); cout<<"The sum is "<<sum; return 0; } //output is //The sum is 0.

EX 16

//write a program and find sum this series // s = 2/4 + 4/8 + 6/12 + 8/16 + n/2n #include using namespace std; int main() { float i,sum=0; int n; cout<<"enter the number "<<endl; cin>>n; for(i=2;i<=n;i=i+2) sum=sum+i/(i*2); cout<<"The sum is "<<sum; return 0; } //output is //enter the number 10 //the sum is 2. EX 17 <----------------------------------------------------------------------> //write a program and find sum this series // S = 2/5 + 4/10 + 6/15 + 8/20 + 10/25 + 12/ #include using namespace std; int main () { float j=0,i,sum=0; for(i=2;i<=12;i=i+2) { j=j+5; sum=sum+i/j; } cout<<"The sum is "<<sum<<endl; return 0; } //output is //the sum is 2.

EX 18

//write a program and find sum this series // S = 1/2 + 2/3 + 3/4 + 4/5 + ....... + n / n+ #include using namespace std ; int main () { int n; float i,sum=0; cout<<"enter the number "<<endl; cin>>n; for(i=1;i<=n;i++) { sum=sum+i/(i+1); } cout<<"The sum is "<<sum; return 0; } //output is //enter the number 6 //the sum is 4. EX 19 <----------------------------------------------------------------------> //write a program and find sum this series //S = 1/2 + 2/4 + 3/8 + 4/16 + 5/32 +.....10/ #include using namespace std; int main () { float j=1,i,sum=0; for(i=1;i<=10;i++) { j=j*2; sum=sum+(i/j); } cout<<"the sum is "<<sum<<endl; return(0); } //output is //the sum is 1.

EX 22

//Example print numbers 1 to 10 #include using namespace std; int main () { int i = 0; while ( i < 10 ) { cout << i; i ++; } return 0; } //Output: //0 1 2 3 4 5 6 7 8 9 EX 23 <----------------------------------------------------------------------> //Example #include using namespace std; int main () { int i = 0; while ( i < 10 ) { cout << i; i=i+2; } return 0; } //Output: even numbers only //0 2 4 6 8 EX 24 <----------------------------------------------------------------------> //Example #include using namespace std; int main () { int i = 1; while ( i < 10 ) { cout << i; i=i+2; } return 0; } //Output: odd numbers only //1 3 5 7 9

EX 25

//Write C++ program to find the summation of the following series: //sum = 1 + 3 + 5 + 7 + … + 99 //in other words: find the summation of the odd numbers, between 0 and 100) #include using namespace std; int main( ) { int count = 1; int sum = 0; while ( count <= 99 ) { sum = sum + count; count = count + 2; } cout << "sum is: " << sum << endl; return(0); } //output //sum is: 2500 EX 26 <----------------------------------------------------------------------> //Write C++ program to find the summation of student’s marks, and //it’s average, assume the student have 8 marks: #include using namespace std; int main( ) { int mark,i,sum = 0; float avg; i = 1; while ( i <= 8 ) { cout << "enter mark: "; cin >> mark; sum = sum + mark; i++; } cout << "sum is: "<< sum << endl; avg = sum / 8; cout << "average is: " << avg; return 0; }