5)
#include <iostream>
using namespace std;
int main()
{
int x=4,y=5;
int a[10]={1,2,3,x,5,6,7,8,9,y};
int i=0,s=0;
while(i<10) //possible values are 0,3,6,9
{
s=s+a[i];
i=i+3;
}
cout << s << endl; //a[0]+a[3]+a[6]+a[9]
return 0; //1 +x (4) +7 +y(5)
}
6)
#include <iostream>
using namespace std;
int main()
{
int x=10,y=20;
int a[10]={-1,2,x,7,-4,11,-2,-y,3,-9};
int s=0;
for(int i=0;i<10;i++)
{
if(a[i]<0)
s+=a[i]; //a[0]+a[4]+a[6]+a[7]+a[9]
// -1 + -4 +-2 + -20(y)+-9=>-36
}
cout << s << endl;
return 0;
}
7)
int *p=new int(200);
8)
#include <iostream>
using namespace std;
int main()
{
int x=10,y=20;
int a=56;
int b=38;
int u=0;
if(a>b)
u=b+x;
else
u=a+y;
cout << u << endl;
return 0;
}
5. (6 pts) What is the outputs of following section of a program? int a[10] =...
5. What is the output of the following section of a program int a[10] = {2,5,1,6,x,7,0,3,y,8}; for(int i=0;i<9;i++) a[i]=a[i+1]; for(int i=0;i<8;i++) cout<<a[i]<<” “; cout<<endl; 6. What will be shown on the output screen after following statements are executed? char a[ ]="I have a part time job"; int c=x, i=0 while(a[i]!=’\0’){ if(a[i]==' '){ c++; cout<<endl; } else cout<<a[i]; i++; } cout<<c<<endl; 7. After following statements are executed, what are the outputs char a[ ]= "Fresno City College"; for (i...
5. (7 pts) What wil display on the output screen after following program is executed? includeciostream using namespace std int b 40 int A function(int a) int main (void) int c 7, b 15 cout<cA function (e) <cendla return 6 int A function (int a) int i cout<<b<<endl; if (a>-0) else return i i-ai i--ai Ans5 6. (7 pts) Show what will appear on the output screen after the following program is executed tincludeciostream> using namespace std; void A function...
4. (10 pts) Show the output of the following program: (list the program outputs in the order as they would appear on screen) #include <iostream> using namespace std; int Mystery(int); int main() int x=2, y: y=Mystery(x - 1)+1; cout << "x="«x«", y="«y < endl; y=Mystery( 2 *x); cout << "x="«x«", y="«y < endl; return 0; int Mystery (int num) int y=5; // This is a regular local variable, not a static local variable int result; y=y+num; cout << "y=" <y<",...
16 Points) Question 3 Write down the outputs of the following program into the provided table include <iostream> using namespace std; void fun I(int a); int fun2(int a, int b); int x-3: int main) int x-1,y 0,z-2; x-fun2(y,z); cout sx fun 1 (z); cout (#xtytz(endl; y-fun2(x,x); cout <exty+zscendl; system("pause"); void fun 1 (int a) int fun2(int a, int b) int static c2; return atx;
16 Points) Question 3 Write down the outputs of the following program into the provided table...
howthe output of the following 4 program segments (a) const int SIZE=8; int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8}; int index; index=0; res = values[index]; for (int j=1; j<SIZE; j++) { if (values[j] > res) { res = values[j]; index = j; cout << index << res << endl; } } cout <<...
Consider the following C++ program: #include <iostream> #include <cstdlib> using namespace std; int main int n =0; int i = 0; cout << "Please enter a strictly positive number:"; cin >> n if (n <= 0) exit(EXIT_FAILURE) while (n > 1) n-n/2; i << endl; cout"Output:" return 0; Answer the following questions: What is the output of the program for each of the following values of n: -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9? What does...
What is the value of result after the following code executes? int a = 60; int b = 15; int result = 20; if (a = b) result *= 3; 30 20 60 10 code will not execute The numeric data types in C++ can be broken into two general categories which are integers and floating-point numbers singles and doubles real and unreal numbers numbers and characters numbers and literals Which line in the following program will cause a compiler error?...
Example (4) Trace the following program and find the output >> SOURCE CODE #include <iostream.h> int main0 // define two integers int x-3; int y = 4; //print out a message telling which is bigger if (x >y) i cout << "x is bigger than y" << endl: else cout << "x is smaller than y" << endl; return 0; Example (5) Write a C++ program that takes from the user a number in SR (Saudi Riyal) then the program...
C++ output
6) What is the exact output of the following program? #include <iostream> using namespace stdi void zolo(int &a, int sb) int main int x = 5, y =8; zolo(x,y)i cout << "x " << x << endl ; cout << "y = "" << y << endl ; return o: void zolo(int &a, int &b) int v1 = b + a; ' int v2 = b-a; 3 a=v1;13
Consider the following program: # include <iostream> int x = 3, y = 5; void foo(void) { x = x + 2; y = y + 4; } void bar(void) { int x = 10; y = y + 3; foo( ); cout << x << endl; cout << y << endl; } void baz(void) { int y = 7; bar( ); cout << y << endl; } void main( ) { baz( ); } What output does this program...