Problem: You have just put in a new garden for your summer plants and would like
ID: 3538078 • Letter: P
Question
Problem: You have just put in a new garden for your summer plants and would like to add a decorative edging around it. The problem is that you have three different shapes left over from a previous similar project and you don't believe using more than any two different shapes would look good around your garden. Determine the longest string of exactly two alternative shapes you could assemble given the quantity of each shape you have available.
SAMPLE EXECUTION:
Enter number of bricks: 2
Enter number of spheres: 5
Enter number of prisms: 1
Longest possible string of alternating shapes using only two different shapes: 5
SAMPle EXECUTION 2:
What is the logic ? **WE CANNOT USE IF/ELSE STATEMENTS, OR SELECTION" No user defined functions.
Use the basic math operators +, -, *, /, %. Hint: ratios!
Explanation / Answer
#include<stdio.h>
#define MIN(num1, num2) ((num1 < num2) ? num1 : num2)
#define MAX(num1,num2) ((num1 > num2) ? num1 : num2)
void main(){
int b,s,p;
int min,mid,max;
scanf("%d %d %d",&b,&s,&p);
(b = MIN(b,s) && b = MIN(b,p))? (min = b,max = MAX(s,p),mid=MIN(s,p)):(min=MIN(s,p),max=MAX(b,MAX(s,p)),mid=MIN(b,MAX(s,p)));
(mid == max )? printf("answer is %d",(2*mid)):printf("answer is %d",(2*mid+1));
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.