Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int MAX(float arr[],int length)
- {
- int i = 0,index=0;
- float maxx = arr[0];
- for(i=1 ; i<length ; i++)
- if(maxx < arr[i])
- {
- maxx = arr[i];
- index = i;
- }
- return index;
- }
- int main()
- {
- int len = 10;
- int max_price = 0;
- int i;
- int x =0;
- int length[10] = {1,2,3,4,5,6,7,8,9,10};
- int pr[10] = {3,4,10,11,13,18,19,22,25,27};
- float r[10];
- for(i=0;i<10;i++){
- r[i]= pr[i]*1.0/length[i];
- //printf("%f\n",r[i]);
- }
- while(len){
- int y = MAX(r,len);
- int x= len/(y+1);
- max_price = max_price + pr[y] * x;
- len = len%(y+1);
- }
- printf("%d",max_price);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement