Untitled
unknown
plain_text
5 months ago
1.2 kB
4
Indexable
#include <stdio.h> int main() { int m, n; int p, q; int matrix[8][10]; int i, j; int count = 0; // Step 1: Input matrix dimensions printf("Enter the number of rows (m <= 8): "); scanf("%d", &m); printf("Enter the number of columns (n < 10): "); scanf("%d", &n); if (m > 8 || n >= 10) { printf("Invalid matrix dimensions.\n"); return 1; } // Step 2: Input matrix elements printf("Enter the elements of the matrix:\n"); for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { scanf("%d", &matrix[i][j]); } } // Step 3: Input the interval [p, q] printf("Enter the interval [p, q]:\n"); printf("p = "); scanf("%d", &p); printf("q = "); scanf("%d", &q); // Step 4: Count the elements in the interval [p, q] for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (matrix[i][j] >= p && matrix[i][j] <= q) { count++; } } } // Step 5: Output the result printf("The number of elements in the interval [%d, %d] is: %d\n", p, q, count); return 0; }
Editor is loading...
Leave a Comment