Viết chương trình tao menu co 4 chức năng 1.in day số fibonancy 2. quản lý học sinh (hoten,diachi,tuoi,diemvan,diemtoan,dtb) 3. thoát

#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
struct sinhvien
{
 char hoten[30];
 char diachi[30];
 int tuoi;
 float toan;
 float van;
 float dtb;
}sv[100],tam;
     int menu(void);
  int n,i,chon;
     void nhap(void);
     void xem(void);
     void sx(void);
     void dayso(void);
main()
{
 for(;;)
 {
  chon=menu();
  switch(chon)
  {
   case 1:dayso();
   break;
   case 2:nhap();
   break;
   case 3:xem();
   break;
   case 4:sx();
   break;
   case 5:exit(0);
  }
 }
}
int menu(void)
{
 int c;
 char s[10];
 printf("1. xem day fibonancy ");
 printf("\n2. nhap danh sach ");
 printf("\n3. xem danh sach ");
 printf("\n4. sap xep danh sach ");
 printf("\n5. thoat\n");
 
 do{
  printf("\n\tMoi ban chon 1/2/3/4/5 = ");
  gets(s);
  c=atoi(s);
 }while(c<1||c>5);
   return c;
}
void nhap(void)
{
 int tuoi;
 printf("\n nhap vao so luong sinh vien = ");
 scanf("%d",&n);
 for(int i=1;i<=n;i++)
 {
  printf("\nnguoi thu %d",i);
  printf("\n nhap vao ho ten : ");
   fflush(stdin);
  gets(sv[i].hoten);
  printf("\n nhap vao dia chi: ");
   fflush(stdin);
  gets(sv[i].diachi);
  printf("\n nhap vao so tuoi : ");
   fflush(stdin);
  scanf("%d",&sv[i].tuoi);
  printf("\n nhap vao diem mon toan :");
   fflush(stdin);
  scanf("%f",&sv[i].toan);
  printf("\n nhap vao diem mon van :");
   fflush(stdin);
  scanf("%f",&sv[i].van);
  sv[i].dtb=(sv[i].toan+sv[i].van)/2;
 }
}

void xem(void)
{
 printf("STT       ho ten         dia chi          tuoi        dtb \n");
 for(int i=1;i<=n;i++)
 {
  printf("\n %d      %s        %s           %d          %.3f ",i,sv[i].hoten,sv[i].diachi,sv[i].tuoi,sv[i].dtb);
 }
 getch();
}

void sx(void)
{
   
   for(i=0;i<=n-1;i++)
   for(int j=i+1;j<=n;j++)
   if(strcmp(sv[i].hoten,sv[j].hoten)>0)
   {
    tam=sv[i];
    sv[i]=sv[j];
    sv[j]=tam;
   }
   printf("\tda sap xep xong bam 2 de xem lai nhe !!\n");   
}
void dayso(void)
{
 
 int n;  int i, x = 0, y = 1, z;

 printf("Ban hay nhap so phan tu trong day Fibonancy: ");  
 scanf("%d",&n); 

      if (n == 1 || n == 2) 
  {
    printf("0  1   ");
  }
     else
        {
          printf("0   1   ");
     for(i=3;i<=n;i++)
      {
            z = x + y;
            x = y;
            y = z;
           printf("%d   ",z);
      }
      printf("\n");
        }
      getch(); 
}

Mới hơn Cũ hơn