Advertisement
Guest User

Modified

a guest
Jan 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1. /* You do not ever need conio.h, it is obsolete! */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. /* Slightly modified prototype */
  6. int R(int N,int M, float **matris);
  7.  
  8. int main(void) {
  9.     int i,j,c,N,M,count;
  10.     float **matris;
  11.    
  12.     printf("Define array size(NxM): ");
  13.     scanf("%d  %d", &N,&M);
  14.     matris=(float **)malloc(N*sizeof(int));
  15.     for(i=0;i<M;i++) {
  16.         matris[i]=(float *)malloc(N*sizeof(int));    
  17.     }
  18.     //read(N,M);
  19.     /* Must get count of negative from function return*/
  20.     count = R(N,M,matris);
  21.     if(count==0)
  22.         printf("There are no negative numbers in array.\n");
  23.     else
  24.         printf("Number of negative values: %d\n",count);
  25.     return 0;
  26. }
  27.  
  28. /* Return value is an integer, the count of negatives */
  29. int R(int N,int M, float **matris) {
  30.     int i,j,count=0; /* You must initialize count to 0 */
  31.    
  32.     for(i=0;i<N;i++) {
  33.         for(j=0;j<M;j++) {
  34.             printf("Please enter value of array[%d][%d] :",i,j);
  35.             /* Matris is a float array! */
  36.             scanf("%f",&matris[i][j]);
  37.         }
  38.     }
  39.    
  40.     for(i=0; i<N; i++) {
  41.         for(j=0;j<M;j++) {
  42.             //printf(" %f ", matris[i][j]);
  43.             if(matris[i][j]<0) {
  44.                 /* You can not do this as num2 is not an array! */
  45.                 //*num2[count]=matris[k][l];
  46.                 count++;
  47.             }
  48.         }
  49.         //printf("\n");
  50.     }
  51.  
  52.     return count;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement