c - Building error leads the Code Blocks to quit -
i'm writing c code solve numerical problem, define 100x100 matrix , fill values matrix, b solution : a[i][j]=1/(i+j+1) , b[i]= sum of values in ith row following code:
#include <stdio.h> #include <stdlib.h> #define n 100 int main() { double a[n][n]; double b[n]; int i,j; (i=0;i<n;i++) (j=0;j<n;j++) { b[i]=0; a[i][j]=0; } (i=0;i<n;i++) (j=0;j<n;j++) { a[i][j]=1/(i+j+1); b[i]+=a[i][j]; } int c=10; (i=0;i<n;i++) (j=0;j<n;j++) { printf("%lf\t",a[i][j]); if (c==j) printf("\n"); c=c*10; } return 0; }
whenever click on build button code blocks terminates, shows :
cross platform ide stopped working
and program closes. can me figure out problem?!
you have problem a
set 0, juste use 1.
use double instead of int
#include <stdio.h> #include <stdlib.h> #define n 100 int main() { double a[n][n]; double b[n]; int i, j; (i = 0; < n; i++) (j = 0; j < n; j++) { b[i] = 0; a[i][j] = 0; } (i = 0 ; < n; i++) (j = 0; j < n; j++) { a[i][j] = 1. / (i + j + 1); b[i] += a[i][j]; } int c = 10; (i = 0; < n; i++) (j = 0; j < n; j++) { printf("%lf\t", a[i][j]); if (c == j) printf("\n"); c *= 10; } return 0; }
Comments
Post a Comment