You are on page 1of 2

#include<iostream.h> #include<string.

h> void main () { struct product { char name[15]; float price; }pr[5];

for (int i=0;i<5;i++) {cout<<"enter the name of product no"<<i+1<<endl; cin>>pr[i].name;} for (int j=0;j<5;j++) {cout<<"enter the price of product no"<<j+1<<endl; cin>>pr[j].price; }

for (int m=4;m>0;m--) { for (int n=0;i<m;n++){ if(pr[n].price>pr[n+1].price) { pr[n].price=pr[n+1].price; strcpy(pr[n].name,pr[n+1].name); } }

} cout<<"the name of products in ascending order of prices are"<<endl; for (int k=0;k<5;k++) cout<<pr[k].name<<endl;

You might also like