Advertisement
Niloy007

Pranto's problem 1

May 17th, 2021 (edited)
905
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. struct student {
  5.     int roll_no;
  6.     char name[50];
  7.     int age;
  8.     char address[200];
  9. };
  10. const int total_student = 5;
  11. struct student s[total_student];
  12.  
  13. void info_by_name() {
  14.     char test_name[50];
  15.     printf("Enter the name to see the details of the student\n");
  16.     fflush(stdin);
  17.     gets(test_name);
  18.     fflush(stdout);
  19.     int flag = 1;
  20.     for (int i = 0; i < total_student; i++) {
  21.         if (strcmp(test_name, s[i].name) == 0) {
  22.             if (flag) {
  23.                 printf("Student's information\n");
  24.             }
  25.             printf("Name: %s\n", s[i].name);
  26.             printf("Roll: %d\n", s[i].roll_no);
  27.             printf("age: %d\n", s[i].age);
  28.             printf("Address: %s\n", s[i].address);
  29.             flag = 0;
  30.         }
  31.     }
  32.     if (flag) {
  33.         printf("No studnet found!\n");
  34.     }
  35. }
  36.  
  37. void info_by_age() {
  38.     int flag = 1;
  39.     for (int i = 0; i < total_student; i++) {
  40.         if (s[i].age == 14) {
  41.             if (flag) {
  42.                 printf("Student's information who have age 14\n");
  43.             }
  44.             printf("%s\n", s[i].name);
  45.             flag = 0;
  46.         }
  47.     }
  48.     if (flag) {
  49.         printf("No studnet found!\n");
  50.     }
  51. }
  52.  
  53. int main() {
  54.     printf("Enter student information:\n");
  55.     for (int i = 0; i < total_student; i++) {
  56.         printf("Enter roll no: ");
  57.         scanf("%d", &s[i].roll_no);
  58.         printf("Enter name: ");
  59.         fflush(stdin);
  60.         gets(s[i].name);
  61.         fflush(stdout);
  62.         printf("Enter age: ");
  63.         scanf("%d", &s[i].age);
  64.         printf("Enter address: ");
  65.         fflush(stdin);
  66.         gets(s[i].address);
  67.         fflush(stdout);
  68.     }
  69.     info_by_name();
  70.     printf("\n");
  71.     info_by_age();
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement