Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You do not ever need conio.h, it is obsolete! */
- #include <stdio.h>
- #include <stdlib.h>
- /* Slightly modified prototype */
- int R(int N,int M, float **matris);
- int main(void) {
- int i,j,c,N,M,count;
- float **matris;
- printf("Define array size(NxM): ");
- scanf("%d %d", &N,&M);
- matris=(float **)malloc(N*sizeof(int));
- for(i=0;i<M;i++) {
- matris[i]=(float *)malloc(N*sizeof(int));
- }
- //read(N,M);
- /* Must get count of negative from function return*/
- count = R(N,M,matris);
- if(count==0)
- printf("There are no negative numbers in array.\n");
- else
- printf("Number of negative values: %d\n",count);
- return 0;
- }
- /* Return value is an integer, the count of negatives */
- int R(int N,int M, float **matris) {
- int i,j,count=0; /* You must initialize count to 0 */
- for(i=0;i<N;i++) {
- for(j=0;j<M;j++) {
- printf("Please enter value of array[%d][%d] :",i,j);
- /* Matris is a float array! */
- scanf("%f",&matris[i][j]);
- }
- }
- for(i=0; i<N; i++) {
- for(j=0;j<M;j++) {
- //printf(" %f ", matris[i][j]);
- if(matris[i][j]<0) {
- /* You can not do this as num2 is not an array! */
- //*num2[count]=matris[k][l];
- count++;
- }
- }
- //printf("\n");
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement