Professional Documents
Culture Documents
M.Shafi Ullah Khan-PF-Assignment 3
M.Shafi Ullah Khan-PF-Assignment 3
1). The program should allow the user to input runs of a cricket innings.
3). Legitimate inputs are 0-6 for runs, and -1 for OUT.
5). If the user enters any other number for runs, the ball should not be considered and runs
input for the same ball should be taken again. (Hint: do not let your iteration variable
increment in this case)
6). The innings should be ended if runs on 300 balls have been added or if 10 players have
been considered OUT. (Hint: Maintain a count of wickets also)
7). The program should display total score after each ball.
8). The program should display “End of Innings” once the innings has been ended.
Ans).
#include<iostream>
int main()
int runs, i;
cout << "Enter Runs of " << "Player no " << player << ":
";
cin >> runs;
Total_runs += runs;
else
wickets++;
player++;
if (runs > 6)
i--;
if (wickets == 10)
break;
Outputs:
When a user enters runs and ten players have been dismissed. Then the innings will end.
When a user enters runs on 300 balls. Then the innings will end.
Problem 2:
Write a C++ program where the user tells a range and your program should display the
following:
4. Sum of the numbers greater than 75 in that range (Hint: this may not even fall in the range)
Ans)
#include<iostream>
int main()
{
if (i % 2 == 0)
sum_E += i;
else
sum_O += i;
if (i % 5 == 0)
sum_5 += i;
if (i > 75)
sum_75 += i;
cout << "Sum of all Even numbers in the range: " << sum_E <<
endl;
cout << "Sum of all Odd numbers in the range: " << sum_O <<
endl;
cout << "Sum of all Multiples of 5 in the range: " << sum_5 <<
endl;
cout << "Sum of all Numbers greater than 75 in the range: " <<
sum_75 << endl;
Outputs:
Take a number as input from the user, and display its multiplication table from 1 to 10.
Ans).
Code:
#include<iostream>
using namespace std;
int main()
{
int number;
cout << "Enter number: ";
cin >> number;
cout << "Table of " << number << ": " << endl;
for (int i = 1; i <= 10; i++)
{
cout << number << " * " << i << " = " << number * i <<
endl;
}
}
Output:
Table of 85