Quantcast
Channel: Active questions tagged return-value - Stack Overflow
Viewing all articles
Browse latest Browse all 228

My program works fine but does not return 0

$
0
0
#include <stdio.h>#include <math.h>#include <time.h>#include <stdlib.h>int i,j;void display_matrix(int matrix[],int rows,int colombs){    for(i=0;i<rows;i++){     for(j=0;j<colombs;j++)        printf("%5d ",matrix[i*rows+j]);    printf("\n");    }}int *create_matrix(int rows,int colombs,int min,int max){    int *matrix=NULL;    matrix=(int*)calloc(colombs*rows,sizeof(int));    for(i=0;i<rows;i++)        for(j=0;j<colombs;j++)            matrix[i*rows+j]=(rand()%(max-min+1))+min;    return matrix;}int main(){    int *m=NULL,row,col;    do{        printf("Give the number of rows:\n");        scanf("%d",&row);    }while(row<=0);    do{        printf("Give the number of colombs:\n");        scanf("%d",&col);    }while(col<=0);    m=create_matrix(row,col,10,99);    display_matrix(m,row,col);    return 0;}

The matrix is displayed as intended but the program return value is 3221226356. I tried changing the rows and colombs in the function create_matrix() and the return value was 0 but the matrix had trash data.

That is the result after i run the program:That is the result after i run the program


Viewing all articles
Browse latest Browse all 228

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>