LOOPS OR ITERATIONS SERIES IN C LANGAUGE Setting

  • Slides: 10
Download presentation
LOOPS OR ITERATIONS SERIES IN C++ LANGAUGE Setting By : A. L. Waleed Rasheed

LOOPS OR ITERATIONS SERIES IN C++ LANGAUGE Setting By : A. L. Waleed Rasheed

Q//W. P. to find y value: #include<iostream. h> #include<math. h> void main() { int

Q//W. P. to find y value: #include<iostream. h> #include<math. h> void main() { int i, j, n, x, r; double y; r=1; cin>>x>>n; for(i=2; i<=n; i+=2) { y+=(pow(x, i)/i)*r; r*=-1; } cout<<"y="<<y; } ﺍﺫﺍ ﻛﺎﻥ ﺍﻭﻝ ﺣﺪ ﺳﺎﻟﺐ ﻳﺠﺐ ﺍﻥ ﺗﻜﻮﻥ r = -1 A. L. Waleed Rasheed

Q / write a program to read the 100 number, and then calculate the

Q / write a program to read the 100 number, and then calculate the average to positive elements and negative elements? #include<iostream. h> void main() { int i, x, k 1, s 1, k 2, s 2; k 1=k 2=s 1=s 2=0; for(i=1; i<=100; i++) { cin>>x; if(x>=0) { s 1+=x; k 1++; } else { s 2+=x; k 2++; } } cout<<"average to Pos. No. ="<<s 1/k 1; cout<<"n average to Neg. No. ="<<s 2/k 2; } A. L. Waleed Rasheed

Q / write a program to read the 100 number, and then calculate the

Q / write a program to read the 100 number, and then calculate the average even positive elements? #include<iostream. h> void main() { int i, x, k 1, s 1; k 1=s 1=0; for(i=1; i<=100; i++) { cin>>x; if(x>=0 && x%2==0) { s 1+=x; k 1++; } } cout<<"average to even Pos. No. ="<<s 1/k 1; } A. L. Waleed Rasheed

 ﺍﻟﺤﻠﻘﺎﺕ ﺍﻭ ﺍﻟﺘﻜﺮﺍﺭﺍﺕ - Loops OR Iterations : Q//what’s output: #include<iostream. h> void

ﺍﻟﺤﻠﻘﺎﺕ ﺍﻭ ﺍﻟﺘﻜﺮﺍﺭﺍﺕ - Loops OR Iterations : Q//what’s output: #include<iostream. h> void main() { int i, j; for(i=4; i>=1; i--) { for(j=1; j<=i; j++) cout<<"*"; cout<<endl; } } (1) -------**** ** * A. L. Waleed Rasheed

 ﺍﻟﺤﻠﻘﺎﺕ ﺍﻭ ﺍﻟﺘﻜﺮﺍﺭﺍﺕ - Loops OR Iterations : Q//what’s output: #include<iostream. h> void

ﺍﻟﺤﻠﻘﺎﺕ ﺍﻭ ﺍﻟﺘﻜﺮﺍﺭﺍﺕ - Loops OR Iterations : Q//what’s output: #include<iostream. h> void main() { int i, j; for(i=1; i<=4; i++) { for(j=1; j<=4; j++) cout<<i*2; cout<<endl; } } (2) -------2222 4444 6666 8888 A. L. Waleed Rasheed

 ﺍﻟﺤﻠﻘﺎﺕ ﺍﻭ ﺍﻟﺘﻜﺮﺍﺭﺍﺕ - Loops OR Iterations : Q//what’s output: #include<iostream. h> main()

ﺍﻟﺤﻠﻘﺎﺕ ﺍﻭ ﺍﻟﺘﻜﺮﺍﺭﺍﺕ - Loops OR Iterations : Q//what’s output: #include<iostream. h> main() { int i, j, m=0; for(i=1; i<=4; i++) { for(j=1; j<=4; j++) cout<<++m; cout<<endl; } } (3) ---------1234 5678 9 10 11 12 13 14 15 16 A. L. Waleed Rasheed

H. W. // Q 1//W. P. to find y value: Q 2//W. P. to

H. W. // Q 1//W. P. to find y value: Q 2//W. P. to find y value: Q 3//write program to print the following: (4) (5) -------* ******* *** ******* * (6) ------1234 2345 3456 4567 A. L. Waleed Rasheed