0% found this document useful (0 votes)
486 views

UAB - 2005 - Problem 4 - Push Ups With Blaze - Solved Programming Problems

This document describes a programming problem to calculate the number of pushups Blaze does after football games based on the final score. It prompts the user to enter a final score, and then calculates how many pushups Blaze would have done by adding 7 pushups for each touchdown, up to the total score. It provides sample inputs and outputs, the C++ code to solve it using a for loop, and discussions on solutions in other languages like Ruby and Golang.

Uploaded by

reddeppa reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
486 views

UAB - 2005 - Problem 4 - Push Ups With Blaze - Solved Programming Problems

This document describes a programming problem to calculate the number of pushups Blaze does after football games based on the final score. It prompts the user to enter a final score, and then calculates how many pushups Blaze would have done by adding 7 pushups for each touchdown, up to the total score. It provides sample inputs and outputs, the C++ code to solve it using a for loop, and discussions on solutions in other languages like Ruby and Golang.

Uploaded by

reddeppa reddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems

UAB – 2005: Problem 4: Push


Ups with Blaze

JULY 27, 2009AUGUST 8, 2013 / SHAHAB

i
4 Votes

At UAB football games, Blaze does push ups after each Blazer score.
After the first Blazer touchdown (and point after), Blaze does 7
push ups. After the second touchdown and point after, the score is
now 14 and Blaze does 14 push ups.

Write a program that calculates how many total push ups Blaze
does during the whole game. Assume that only 7 point touchdowns
(including the point after) occur. Prompt for the final score and
print out how many push ups Blaze has done.

Example 1:
Enter final score: 21
Push ups: 42

Example 2:
Enter final score: 7
Push ups: 7
?
Critical TestCases
https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 1/5
10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems

Critical TestCases
1 Enter final score: 0
2 Push ups: 0
3
4 Enter final score: 14
5 Push ups: 21
6
7 Enter final score: 28
8 Push ups: 70
9
10 Enter final score: 35
11 Push ups: 105
12
13 Enter final score: 42
14 Push ups: 147
?
Solution in C/C++
1 // @BEGIN_OF_SOURCE_CODE
2
3 #include <cstdio>
4
5 using namespace std;
6
7 int main (int argc, char *argv [])
8 {
9 int finalScore;
10 printf ("Enter final score: ");
11 scanf ("%d", &finalScore);
12
13 int pushUps = 0;
14 for ( int i = 7; i <= finalScore; i = i + 7 )
15 pushUps = pushUps + i;
16
17 printf ( "Push ups: %d\n", pushUps );
18
19 return 0;
20 }
21
22 // @END_OF_SOURCE_CODE

https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 2/5
10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems
Advertisements

Easy Problems

5 thoughts on “UAB – 2005: Problem


4: Push Ups with Blaze”

1. Tanvir
APRIL 21, 2011 AT 9:39 PM
plz tell me the problem ID of it in UVA.

i
Rate This

2. Tausiq
APRIL 22, 2011 AT 12:25 AM
@Tanvir
this problem is from a high school programming contest .. not
from UVa online judge

i
Rate This
3. Lenz Lawson
https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 3/5
10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems

3. Lenz Lawson
JANUARY 11, 2016 AT 12:15 AM
this a typical beginner’s program for this problem:

#include
int main()
{
int score,i,pushup=0;
printf(“please enter the final score: “);
scanf(“%d”,&score);
printf(“\n”);
if(score%7==0){
for(i=1;i<=score/7;i++){
pushup=pushup+7*i;
}
}
else{
printf(" please enter a multiple of 7.\n");
}
printf("\n");
printf("the total number of push-ups is %d",pushup);
printf("\n");
return 0;
}

i
Rate This

4. Mike Blap
APRIL 5, 2017 AT 6:20 AM
I think I have this working in Golang:

package main

import (
“fmt”
)

func main() {
score := 21
tally := tally(score)
fmt.Println(tally)
}

func tally(score int) int {


https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 4/5
10/23/2017 UAB – 2005: Problem 4: Push Ups with Blaze | Solved Programming Problems

func tally(score int) int {


div := score / 7
var hm int
for div > 0 {
hm += 7 * div
div -= 1
}
return hm
}

i
Rate This

5. ljnissen
AUGUST 21, 2017 AT 3:30 PM
This is my Ruby solution:

print “Final score: ”


score = gets.to_i
touchdowns = score / 7
pushups = 0

(1..touchdowns).each do |i|
i +=
pushups = pushups + 7*i
end
print “Number of push-ups: “, pushups

i
Rate This

https://tausiq.wordpress.com/2009/07/27/uab-2005-problem-4-push-ups-with-blaze/ 5/5

You might also like