{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Test_3 - k<6 k cout<<a[k<<""...

Info icon This 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()
Image of page 1

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

View Full Document Right 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
Image of page 2
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern