Sita shortlists 4 gifts priced at Rs.r1, Rs.r2, Rs.r3 and Rs.r4 respectively. She wants to buy 3 of these gifts such that it doesn't exceed her budget of Rs.x.
Identify the choices - one where she could save more money and the other where she could spend the maximum amount within the planned budget.
Can you please help her?
Input Format:
Input consists of 5 integers that correspond to r1, r2, r3, r4 and x.
Output Format:
The output consists of 2 integers. The 1st integer corresponds to the minimal amount she would spend on buying 3 gifts. The 2nd integer corresponds to the maximal amount she would spend on buying 3 gifts.
Sample Input :
20
30
10
25
80
Sample Output :
55
75
Program Code:
#include<stdio.h>
int main()
{
int R1,R2,R3,R4,budget,f,g,h,i,mini,maxi;
scanf("%d%d%d%d%d",&R1,&R2,&R3,&R4,&budget);
f=R1+R2+R3;
g=R2+R3+R4;
h=R1+R3+R4;
i=R1+R2+R4;
mini=f;
maxi=0;
if(g<mini)mini=g;
if(h<mini)mini=h;
if(i<mini)mini=i;
if(f>maxi && f<=budget)maxi=f;
if(g>maxi && g<=budget)maxi=g;
if(h>maxi && h<=budget)maxi=h;
if(i>maxi && i<=budget)maxi=i;
printf("%d\n%d\n",mini,maxi);
return 0;
}
This article is an appealing wealth of informative data that is interesting and well-written. I commend your hard work on this and thank you for this information. You’ve got what it takes to get attention.
ReplyDeleteOrder personalised gifts online
Tell me some input for this program
ReplyDelete