Test_3 - k<6 k++) cout<<a[k]<<" "...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 1) #include <iostream> using namespace std int A_function(int a) int main () { int n=10 cout<<A_function(n)<<endl n=15 cout<<A_function(n)<<endl return 0 } int A_function(int a) { int c if(a!=10) c=a else c=a*2 return c } solution: 20 2 2) #include <iostream> using namespace std void A_function(int a, int b) int main (void) { int r=36, s=52 A_function (r,s) cout<<r<<" "<<s<<endl return 0 } void A_function (int a, int b) { int i i=a a=b b=i cout<<a<<" "<<b<<endl } solution: 52 36 52 36 3) void squareroot()
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Sheet1 Page 2 int sum=0 for (int i=0 i<=60 i++){ sum+=i*i } cout<<sum<<endl 7) #include <iostream> using namespace std int main () { int a[6]={2, 6, 3, 7, 1, 5}, t=0 for(int i=0 i<6 i++){ if (a[i+1]<a[i]){ t=a[i] a[i]=a[i+1] a[i+1]=t } } for (int k=0
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: k<6 k++) cout<<a[k]<<" " } 8) #include <iostream> using namespace std int main () { int a[10] = {1,2,3,4,5,6,7,8,9,10} int i=0, s=0 while(i<10){ s=s+a[i] i=i+3 } cout<<s<<endl } solution: 22 9) #include <iostream> using namespace std Sheet1 Page 3 int main () { int a[10] = {1,2,3,4,5,6,7,8,9,10} int i=0, s=0 while(i<10){ cout<<a[i]<<" " i=i+2 } } solution: 1 3 5 7 9 11) #include <iostream> using namespace std int main () { int a[8]={2,5,1,0,0,0,0,0} for (int i=7 i>0 i--) a[i]=a[i -1] for (int k=0 k<8 k++) cout<<a[k]<<" " } solution: 2 2 5 1 0 0 0 0--------------------------------------------------------...
View Full Document

This note was uploaded on 05/16/2010 for the course CISCO EST61 taught by Professor Miller during the Spring '10 term at Fresno City College.

Page1 / 3

Test_3 - k<6 k++) cout<<a[k]<<" "...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online