प्रिंट करें मैं मैट्रिक्स (2 डी सरणी) पढ़ने के लिए 2 फ़ंक्शन लिखने की कोशिश कर रहा हूं, और इसे प्रिंट करने के लिए अन्य। अब तक मेरे पास है:पॉइंटर/मॉलोक का उपयोग करके 2 डी सरणी बनाना, और फिर इसे
/* Read a matrix: allocate space, read elements, return pointer. The
number of rows and columns are given by the two arguments. */
double **read_matrix(int rows, int cols){
double **mat = (double **) malloc(sizeof(double *)*rows);
int i=0;
for(i=0; i<rows; i++){
/* Allocate array, store pointer */
mat[i] = (double *) malloc(sizeof(double)*cols);
//what to do after??
return mat;
}
तो प्रिंट मैट्रिक्स समारोह, यकीन नहीं अगर यह सही
void print_matrix(int rows, int cols, double **mat){
for(i=0; i<rows; i++){ /* Iterate of each row */
for(j=0; j<cols; j++){ /* In each row, go over each col element */
printf("%f ",mat[i][j]); /* Print each row element */
}
}}
है और यहाँ मुख्य कार्य मैं चलाने के लिए उपयोग कर रहा हूँ है:
#include <stdio.h>
#include <stdlib.h>
double **read_matrix(int rows, int cols);
void print_matrix(int rows, int cols, double **mat);
void free_matrix(int rows, double **mat);
int main(){
double **matrix;
int rows, cols;
/* First matrix */
printf("Matrix 1\n");
printf("Enter # of rows and cols: ");
scanf("%d %d",&rows,&cols);
printf("Matrix, enter %d reals: ",rows*cols);
matrix = read_matrix(rows,cols);
printf("Your Matrix\n"); /* Print the entered data */
print_matrix(rows,cols,matrix);
free_matrix(rows, matrix); /* Free the matrix */
return 0;}
वोटिंग बंद करने के लिए है क्योंकि यह stackoverflow के बजाय कोड की समीक्षा stackexchange के लिए एक सवाल की तरह लग रहा है। कोड मूल रूप से ठीक दिखता है, यद्यपि। –
आपकी सटीक समस्या क्या है? मुझे यहां कोई प्रश्न नहीं दिखाई दे रहा है ... – Christoph
@ बेन जैकसन: यह [offackic.com पर offtopic] के रूप में बंद है (http://codereview.stackexchange.com/q/17833/6143)। यह एक अच्छा अनुभव नहीं है। – jfs