Answer the question
In order to leave comments, you need to log in
Why is nothing output from the function?
The task is this:
Given a two-dimensional array, display the sum of all prime numbers in the specified area
. after two cycles we go through all the indicated areas, but for now we are going to calculate the sum of prime numbers and display it immediately on the screen.
Below is an example if the array size is 3 by 5
The compiler stops here:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int A[15][15];
int prime(int n){
int i;
for(i = 2; i < n; i++){
if(n % i == 0){
return 0;
}
}
return 1;
}
void obrabotka (int N, int M){
int k, z, l, f, S, i, j, num, che;
k = 0;
z = 0;
S = 0;
che = 0;
num = 1;
for(k = 0; k < (N - 3); k++){
for(z = 0; z < (M - 3); z++){
i = k;
j = z;
while(i < (k + 3)){
che = prime(A[i][j]);
if(che == 1){
S = S + A[i][j];
}
i++;
j++;
che = 0;
}
printf("|%4d |%3d |%3d |%6d |\n", num, k, z, S);
printf("|------------------------|\n");
num++;
}
}
}
void main ()
{
int N, M, i, j, S;
printf ("vvedite N i M\n");
scanf ("%d %d", &N, &M);
printf ("vvedite matrizu\n");
for (i = 0; i < N; i++){
for (j = 0; j < M; j++){
scanf("%d", &A[i][j]);
}
}
printf("-------------------------\n");
printf("| num | i | j | result|\n");
printf("-------------------------\n");
obrabotka(N, M);
getch();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question