A
A
Alexander Rybakov2018-10-13 20:20:40
C++ / C#
Alexander Rybakov, 2018-10-13 20:20:40

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
5bc2287196383531247222.jpeg
The compiler stops here:
5bc229635bb0b818006487.jpeg

#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();
 }

Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
res2001, 2018-10-13
@turkish777

At least because in your example N = 3, and in obrabotka() the first cycle is declared like this: i.e. there will be no iteration of the loop under such initial conditions. PS: Didn't check everything else.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question