diff --git a/Fractional knapsack b/Fractional knapsack new file mode 100644 index 0000000..d1c5224 --- /dev/null +++ b/Fractional knapsack @@ -0,0 +1,72 @@ +#include +#include +using namespace std; +struct item{ + int val; + int weight; +}; + + +void sort(struct item arr[],int n) +{ + int i,j; + for(i=0;ix) + { + int temp=arr[j].val; + arr[j].val=arr[j+1].val; + arr[j+1].val=temp; + temp=arr[j].weight; + arr[j].weight=arr[j+1].weight; + arr[j+1].weight=temp; + } + } + } +} + +double Final_Result(struct item arr[],int n,int w) /// function for calculate the final result +{ + sort(arr,n); + int i; + int current=0; + double res=0.0; + for(i=0;i>n; + int capacity; + int i; + item arr[n]; + cout<<"Enter the value and weight of the each item"<<"\n"; + for(i=0;i>arr[i].val; + cin>>arr[i].weight; + } + cout<<"Enter the capacity of the bag"<<"\n"; + cin>>capacity; + cout<