Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX 100
- int main() {
- // Otpechatvane na uslovieto na zadachata
- printf("Programa za obrabotka na dvumeren masiv A[N,N]. Dannite sa celi chisla v intervala [-1000; 1000].\n");
- // Otpechatvane na imenata na avtora
- printf("Avtor: Darina Karaivanova, 171224316, ID, 25b\n");
- int A[MAX][MAX], C[MAX];
- int N, i, j;
- // Vavezhdane na vhodnite danni
- printf("Vavedete razmernost N na dvumerniya masiv (N <= 100): ");
- scanf("%d", &N);
- if (N > MAX) {
- printf("Greshka: Maksimalnata dopustima stoynost na N e %d.\n", MAX);
- return 1;
- }
- printf("Vavedete elementite na dvumerniya masiv A[%d,%d]:\n", N, N);
- for (i = 0; i < N; i++) {
- for (j = 0; j < N; j++) {
- scanf("%d", &A[i][j]);
- if (A[i][j] < -1000 || A[i][j] > 1000) {
- printf("Greshka: Vavedenoto chislo tryabva da e v intervala [-1000, 1000].\n");
- return 1;
- }
- }
- }
- // Otpechatvane na vhodnite danni
- printf("Vavedeniyat dvumeren masiv A[%d,%d]:\n", N, N);
- for (i = 0; i < N; i++) {
- for (j = 0; j < N; j++) {
- printf("%d ", A[i][j]);
- }
- printf("\n");
- }
- // a) Sazdavane na ednomeren masiv C[N]
- for (i = 0; i < N; i++) {
- int positive_count = 0;
- for (j = 0; j < N; j++) {
- if (A[i][j] > 0) {
- positive_count++;
- }
- }
- C[i] = positive_count;
- }
- // Otpechatvane na masiva C sled obrabotka a)
- printf("Masiv C sled obrabotka a):\n");
- for (i = 0; i < N; i++) {
- printf("%d ", C[i]);
- }
- printf("\n");
- // b) Sortirane na masiva C
- for (i = 0; i < N - 1; i++) {
- for (j = i + 1; j < N; j++) {
- if (C[i] > C[j]) {
- int temp = C[i];
- C[i] = C[j];
- C[j] = temp;
- }
- }
- }
- // Otpechatvane na masiva C sled obrabotka b)
- printf("Masiv C sled obrabotka b):\n");
- for (i = 0; i < N; i++) {
- printf("%d ", C[i]);
- }
- printf("\n");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement