Advertisement
venik2405

lab1_2_yap_final

Sep 24th, 2021
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #define size 6
  3.  
  4. void main(void) {
  5. int M[size][size];
  6. int i, j, a, flag, ind;
  7. for (i = 0; i < size; i++) {
  8. for (j = 0; j < size; j++) {
  9. do {
  10. do {
  11. rewind(stdin);
  12. printf("Enter element with index [%d|%d]: ", i + 1, j + 1, "\n");
  13. ind = scanf_s("%d", &a);
  14. if (ind != 1) {
  15. printf("Incorrect input!!!\n");
  16. }
  17. } while (ind != 1);
  18. if ((a > 100) || (a < -100))
  19. {
  20. printf("Enter the number, which is higher than -100 and lower than 100");
  21. flag = 1;
  22. }
  23. else {
  24. flag = 0;
  25. }
  26. } while (flag == 1);
  27. M[i][j] = a;
  28. }
  29. }
  30. printf("Your matrix: \n");
  31. for (i = 0; i < size; i++) {
  32. for (j = 0; j < size; j++) {
  33. printf(" %d", M[i][j]);
  34. }
  35. printf("\n");
  36. }
  37. int num = M[0][0];
  38. for (i = 0; i < size; i++) {
  39. for (j = 0; j < size; j++) {
  40. if (M[i][j] >= num) {
  41. num = M[i][j];
  42. }
  43. }
  44. }
  45. printf("The biggest number is %d\n", num);
  46. printf("Indexes of the biggest elements from the matrix:\n");
  47. for (i = 0; i < size; i++) {
  48. for (j = 0; j < size; j++) {
  49. if (M[i][j] == num) {
  50. printf("[%d|%d]\n", i + 1, j + 1);
  51. }
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement