0

I'm writing a C code to solve a numerical problem, I define a 100x100 matrix and fill it with values A is the matrix, b is the solution : A[i][j]=1/(i+j+1) , b[i]= the sum of all values in the ith row Following is my code:

#include <stdio.h>
#include <stdlib.h>
#define n 100
int main()
{
    double A[n][n];
    double b[n];
    int i,j;
    for (i=0;i<n;i++)
        for (j=0;j<n;j++)
        {
            b[i]=0;
            A[i][j]=0;
        }
    for (i=0;i<n;i++)
        for (j=0;j<n;j++)
        {
            A[i][j]=1/(i+j+1);
            b[i]+=A[i][j];
        }

    int c=10;

    for (i=0;i<n;i++)
        for (j=0;j<n;j++)
        {
             printf("%lf\t",A[i][j]);
             if (c==j) printf("\n");
             c=c*10;
        }


    return 0;
}

Whenever I click on the build button the Code Blocks terminates, shows this :

Cross platform IDE stopped working

and then the program closes. Can anybody help me to figure out the problem?!

ryyker
  • 22,849
  • 3
  • 43
  • 87
RayaR
  • 11
  • 1
  • I built it (and ran it) in my (non-CodeBlocks) environment. It built/ran fine. Some possibilities might include memory limits (not likely), compiler switch/build settings, bad configuration of CodeBlocks environment. Can you show your build settings? – ryyker Apr 14 '15 at 18:37
  • @ryyker could you please tell me what's the environment you're using? – RayaR Apr 14 '15 at 19:26
  • I am using LabWindows/CVI. It is a commercial product from National Instruments. But I have subsequently run it in Code::Blocks, and it built/ran just fine. – ryyker Apr 14 '15 at 19:33

2 Answers2

0

You have a problem all A will be set to 0, juste use 1. do 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;                                                                  
    for (i = 0; i < n; i++)                                                    
        for (j = 0; j < n; j++)                                                
        {                                                                      
            b[i] = 0;                                                          
            A[i][j] = 0;                                                       
        }                                                                      
    for (i = 0 ; i < n; i++)                                                   
        for (j = 0; j < n; j++)                                                
        {                                                                      
            A[i][j] = 1. / (i + j + 1);                                        
            b[i] += A[i][j];                                                   
        }                                                                      

    int c = 10;                                                                

    for (i = 0; i < n; i++)                                                    
        for (j = 0; j < n; j++)                                                
        {                                                                      
            printf("%lf\t", A[i][j]);                                          
            if (c == j) printf("\n");                                          
            c *= 10;                                                           
        }                                                                      


    return 0;                                                                  
}  
Ôrel
  • 7,044
  • 3
  • 27
  • 46
  • Well, this statement is not the problem I've tried to build the program without it but it also doesn't work – RayaR Apr 14 '15 at 19:26
  • @Ôrel - Although assigning int values to a double variable is sloppy, it is not the issue here. In fact, there is really no issue with the code. I ran it just as it is on my Code::Block environment, and it built and ran just fine. – ryyker Apr 14 '15 at 19:37
0

I have built and run your code, exactly as it is in both my everyday environment (LabWindows/CVI - ANSI C compiler) and in a default Code::Blocks, console project, in debug mode. In both environments, other than having possibly unexpected results, it worked just fine. (you may have some debugging to do once you get it to build).

Suggest taking a look at your Code::Block installation/environment. I have had to re-install before to get it to work right, although that was long ago, and I cannot remember the specifics.

For now, look at:
1) Global Compiler Settings - Toolchain Executables Mine looks like this:
enter image description here

2) Global Compiler Settings - Compiler settings
Mine are all defaulted to Not Selected

3) Global Compiler Settings - Build Options
Mine looks like this:
enter image description here

The run looked like this:
enter image description here

ryyker
  • 22,849
  • 3
  • 43
  • 87