Niloy007

Problem 1

May 25th, 2021 (edited)
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int c = 3, s = 8;
  5.     int list[3][8];
  6.     list[0][0] = 1;
  7.     list[0][1] = 0;
  8.     list[0][2] = 1;
  9.     list[0][3] = 0;
  10.     list[0][4] = 1;
  11.     list[0][5] = 1;
  12.     list[0][6] = 1;
  13.     list[0][7] = 0;
  14.     list[1][0] = 1;
  15.     list[1][1] = 0;
  16.     list[1][2] = 0;
  17.     list[1][3] = 1;
  18.     list[1][4] = 1;
  19.     list[1][5] = 0;
  20.     list[1][6] = 1;
  21.     list[1][7] = 0;
  22.     list[2][0] = 1;
  23.     list[2][1] = 1;
  24.     list[2][2] = 1;
  25.     list[2][3] = 1;
  26.     list[2][4] = 0;
  27.     list[2][5] = 1;
  28.     list[2][6] = 1;
  29.     list[2][7] = 0;
  30.    
  31.  
  32.     printf("Student who have the most number in the class is: ");
  33.     int ans = 0, index = 0;
  34.     for (int i = 0; i < c; i++) {
  35.         int sum = 0;
  36.         for (int j = 0; j < s; j++) {
  37.             sum += list[i][j];
  38.         }
  39.         if (ans < sum) {
  40.             ans = sum;
  41.             index = i;
  42.         }
  43.     }
  44.     printf("%d\n", index);
  45.  
  46.     printf("Student who have enrolled in all the classes are:\n");
  47.     for (int i = 0; i < s; i++) {
  48.         int sum = 0;
  49.         for (int j = 0; j < c; j++) {
  50.             sum += list[j][i];
  51.         }
  52.         if (sum == c) {
  53.             printf("%d ", i);
  54.         }
  55.     }
  56.     printf("\n");
  57. }
  58.  
  59.  
Add Comment
Please, Sign In to add comment