Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Student{
- int ID;
- char name[20];
- int marks;
- };
- void sortByMarks(Student arr[], int length);
- int main(){
- struct Student stu[3];
- for(int i=0; i<3; i++){
- cout<<"Enter ID, name and marks of student "<<i+1<<" : \n";
- cin>>s[i].id>>stu[i].name>>stu[i].marks;
- }
- sortByMarks(stu,3);
- for(int i=0; i<3; i++){
- cout<<stu[i].id<<"\t"<<stu[i].name<<"\t"<<stu[i].marks<<"\n";
- }
- return 0;
- }
- void sortByMarks(Student arr[], int length){
- bool didSwap;
- Student temp;
- do{
- didSwap = false;
- for (int i=0; i<length-1; i++){
- if (arr[i].marks> rr[i+1].marks){
- temp=arr[i];
- arr[i]=arr[i+1];
- arr[i+1]=temp;
- didSwap=true;
- }
- }
- }
- while(didSwap);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement