Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <string.h>
- struct student {
- char nazwisko[30], imie[20];
- char indeks[11];
- int wiek;
- double stypendium;
- char zaliczenie;
- };
- typedef struct student student;
- void wypelnij(struct student* p,int n)
- {
- int i,j,a=1,b;
- double c;
- for(i=0;i<n;i++)
- {
- printf("Podaj nazwisko studenta ");
- a=1;
- while(a!=0)
- {
- scanf("%s",p[i].nazwisko);
- b=strlen(p[i].nazwisko);
- for(j=0;j<b;j++)
- {
- if(isalpha((int)p[i].nazwisko[j]))
- {
- a=0;
- }
- else
- {
- a=1;
- printf("podales bledne nazwisko podaj jeszcze raz ");
- break;
- }
- }
- }
- a=1;
- printf("Podaj imie studenta ");
- while(a!=0)
- {
- scanf("%s",p[i].imie);
- b=strlen(p[i].imie);
- for(j=0;j<b;j++)
- {
- if(isalpha((int)p[i].imie[j]))
- {
- a=0;
- }
- else
- {
- a=1;
- printf("podales bledne imie podaj jeszcze raz ");
- break;
- }
- }
- }
- printf("podaj numer indeksu ");
- a=1;
- while(a!=0)
- {
- scanf("%s",p[i].indeks);
- b=strlen(p[i].indeks);
- if(b==10)
- {
- for(j=0;j<10;j++)
- {
- if(isalnum(p[i].indeks[j]))
- {
- a=0;
- }
- else
- {
- printf("Podales blednie numer indeksu podaj jeszcze raz ");
- a=1;
- break;
- }
- }
- }
- else
- {
- printf("blednie podales numer indeksu podaj jeszcze raz");
- a=1;
- }
- }
- printf("Podaj wiek ");
- a=1;
- while(a!=0)
- {
- scanf("%d",&p[i].wiek);
- if(p[i].wiek>0)
- {
- a=0;
- }
- else
- {
- printf("Blednie podales wiek podaj jeszcze raz ");
- a=1;
- }
- }
- a=1;
- printf("Jezeli student zaliczyl podaj T jezeli nie N");
- scanf("%s",&p[i].zaliczenie);
- while(a!=0)
- {
- if(p[i].zaliczenie=='T')
- {
- a=0;
- }
- else
- {
- if(p[i].zaliczenie=='N')
- {
- a=0;
- }
- else
- {
- printf("Blednie podales zaliczenie podaj jeszcze raz");
- scanf("%c",&p[i].zaliczenie);
- }
- }
- }
- printf("Podaj wielkosc stypendium ");
- a=1;
- while(a!=0)
- {
- scanf("%lf",&c);
- if(c<0)
- {
- printf("Blednie podales stypendium podaj jeszcze raz ");
- a=1;
- }
- else
- {
- a=0;
- p[i].stypendium=c;
- }
- }
- }
- for(i=0;i<n;i++)
- {
- printf("Nazwisko %s\n imie %s\nindeks %s\n wiek %d\nstypendium %lf\nzaliczenie %c\n",p[i].nazwisko,p[i].imie,p[i].indeks,p[i].wiek,p[i].stypendium,p[i].zaliczenie);
- }
- }
- void znajdz(student* p,int n)
- {
- int i;
- double minstypendium=1000000000;
- student l;
- for(i=0;i<n;i++)
- {
- if(p[i].zaliczenie=='T')
- {
- if(p[i].stypendium<minstypendium)
- {
- minstypendium=p[i].stypendium;
- l=p[i];
- }
- }
- }
- printf("%s\n %s\n %s\n %d\n %lf",l.imie,l.nazwisko,l.indeks,l.wiek,l.stypendium);
- }
- int main()
- {
- int n;
- student *p;
- printf("Podaj ile studentow chcesz wprowadzic ");
- scanf("%d",&n);
- p=(student*)malloc(n*sizeof(student));
- wypelnij(p,n);
- znajdz(p,n);
- free(p);
- return 0;
- }
Add Comment
Please, Sign In to add comment