Да се дефинира структура, която съдържа името и фамилията на ученик, и средния му успех за срока. Да се въведе брой на учениците и после данните на всеки един ученик. Накрая да се отпечатат учениците, подредени по успех.
По желание: да се отпечатат и подредени по името или по фамилията.


#include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char** argv) { struct uchenik { char ime[20]; char familiq[20]; double uspeh; }; int br; cout<<"Broi uchenici: "; cin>>br; uchenik uchenici[br]; cout<<"Vavedi ime, familiq i uspeh na uchenik: "<<endl; for(int i=0; i<br; i++){ cout<<"#"<<i+1<<": "; cin>>uchenici[i].ime>>uchenici[i].familiq>>uchenici[i].uspeh; } int swap, imin; for(int i=0; i<br-1; i++){ imin=i; for(int j=i+1; j<br; j++) if(uchenici[j].uspeh<uchenici[imin].uspeh) imin=j; if(imin!=i){ swap=uchenici[i].uspeh; uchenici[i].uspeh=uchenici[imin].uspeh; uchenici[imin].uspeh=swap; } } for(int i=0; i<br; i++){ cout<<uchenici[i].ime<<" "<<uchenici[i].familiq<<" "<<uchenici[i].uspeh<<endl; } system("pause"); return 0; }#include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char** argv) { struct uchenik { char ime[20]; char familiq[20]; double uspeh; }; int br; cout<<"Broi uchenici: "; cin>>br; uchenik uchenici[br]; cout<<"Vavedi ime, familiq i uspeh na uchenik: "<<endl; for(int i=0; i<br; i++){ cout<<"#"<<i+1<<": "; cin>>uchenici[i].ime>>uchenici[i].familiq>>uchenici[i].uspeh; } double swap; int imin; for(int i=0; i<br-1; i++){ imin=i; for(int j=i+1; j<br; j++) if(uchenici[j].uspeh<uchenici[imin].uspeh) imin=j; if(imin!=i){ swap=uchenici[i].uspeh; uchenici[i].uspeh=uchenici[imin].uspeh; uchenici[imin].uspeh=swap; } } for(int i=0; i<br; i++){ cout<<uchenici[i].ime<<" "<<uchenici[i].familiq<<" "<<uchenici[i].uspeh<<endl; } system("pause"); return 0; }Ето я програмата, този път функционираща правилно
#include <iostream> #include <stdlib.h> using namespace std; struct uchenik { char ime[20]; char familiq[20]; double uspeh; }; int main(int argc, char** argv) { int br; cout<<"Broi uchenici: "; cin>>br; uchenik uchenici[br]; cout<<"Vavedi ime, familiq i uspeh na uchenik: "<<endl; for(int i=0; i<br; i++){ cout<<"#"<<i+1<<": "; cin>>uchenici[i].ime>>uchenici[i].familiq>>uchenici[i].uspeh; } uchenik swap; int imin; for(int i=0; i<br-1; i++){ imin=i; for(int j=i+1; j<br; j++) if(uchenici[j].uspeh<uchenici[imin].uspeh) imin=j; if(imin!=i){ swap=uchenici[i]; uchenici[i]=uchenici[imin]; uchenici[imin]=swap; } } for(int i=0; i<br; i++){ cout<<uchenici[i].ime<<" "<<uchenici[i].familiq<<" "<<uchenici[i].uspeh<<endl; } system("pause"); return 0; }Е, така вече е по-добре…