CS101 Midterm2
CS101 Midterm2
CS101 Midterm2
You may ask for extra sheet for rough work, however, it will not be collected
Make sure your provide answers in the space provided. I follow this rule quite strictly!
Follow the conventions discussed in class, correctness alone will not earn you full marks
Q1 - Consider the following C++ program. What is the output from the program in response to the
following user input?
#include <iostream>
using namespace std;
int main()
{
int n, m;
cout << "Please enter two integers: ";
cin >> n >> m;//first entered value gets stored in n, second in m
if (n > m)
cout << n % m << endl;
else
{
for (int r = 1; r < n; r++)
{
for (int c = 1; c < m - n - 1; c++)
{
cout << "*+";
}
cout << endl;
}
}
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int x,quotient=0,remainder,sum,number;
cout << "Input a number ";
cin >> x;
number = x;
remainder = x;
sum=0;
while (x < 10)
{
quotient = x/10;
remainder = x%10;
x = quotient;
sum = sum+ quotient*quotient*quotient ;
}
if (sum==number)
cout << "I have found an amazing Armstrong number";
else
cout << "This is not my amazing Armstrong number";
return 0;
}
#include <iostream>
using namespace std;
int main()
{
//Assume the code to declare and initialize the array is already given here
//from this point you have a declared and populated integer array by the name intArray and
//its size is given to you in an integer MAX_SIZE
(Question 4 continued)