Friday, September 5, 2014
COMPRO1 Hands-on Exam (Set A) - Answer Key
Problem:
Write a program to require an integer input between 1 to 10. Vary and display the control variable of a for-loop statement from 1 to 10 and put a dollar sign ($) in place of that number.
Sample Output #1:
Enter a number between 1 and 10: 6
$$$$$6$$$$
Sample Output #2:
Enter a number between 1 and 10: 2
$2$$$$$$$$
Sample Output #3:
Enter a number between 1 and 10: 9
$$$$$$$$9$
Solution:
#include <iostream>
using namespace std;
int main(){
int n;
cout << "Enter a number between 1 and 10: "
cin >> n;
for (int i=1; i<=10; i++)
{
if (n==i)
cout << "$";
else
cout << i;
}
return 0;
}
Viral Stuff and Trending News
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment