IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Help needed

2 posters

Go down

User verified solution Help needed

Post by BIT0129-Tabassum Sat May 22, 2010 12:08 am

I haven't find any mistake in the following code, indeed I can't get :p
It doesn't show the correct answer. Please check the code and tell me where the logic is incorrect.Please help! I am trying it from last night

Code:

#include
#include
#include


int main(void){

    int n=3,i,j,key;
    double sum,x0[3],x[3];

    double a[3][3]={2,1,1,
                    3,5,2,
                    2,1,4};

    double b[3]={5,15,8};


    printf("Starting...\n");


    for(i=0;i
        x0[i]=b[i]/a[i][i];


        key=0;

      while(key==0){



          for(i=0;i
            {
                sum=b[i];

            for(j=0;j

                if(i!=j)

                sum=sum-(a[i][j]*x0[j]);

                }

                    x[i]=sum/a[i][i];

                if(key==0){
                    if(fabs((x[i]-x[0]))>0.00000001)
                        key=1;
                }

            }
        if(key==1){
            x0[i]=x[i];



          }
      }

    for(i=0;i
        printf("%f\n\n", x[i]);

    printf("END!");


    getch();
    return 0;

    }


Last edited by BIT0129-tabassum on Sat May 22, 2010 1:36 am; edited 1 time in total
BIT0129-Tabassum
BIT0129-Tabassum
Global Moderator
Global Moderator

Course(s) :
  • BIT

Blood Group : A+
Posts : 1496
Points : 2298

http://probe-tabassum.blogspot.com

Back to top Go down

User verified solution Re: Help needed

Post by BIT0122-Amit Sat May 22, 2010 12:49 am

try changing this part
Code:

 while(key==0){



          for(i=0;i<n;i++)
            {

to
Code:

while(key==1){
          key=0;


          for(i=0;i<n;i++)
            {

and from
Code:

 if(key==1){
            x0[i]=x[i];

to this

Code:

if(key==1)
for(i=0;i<3;i++)
   x0[i]=x[i];
}

edit: Oops... i just noticed. you need to initialize value of key as 1 or else it will not even enter in the loop.!!
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

User verified solution Re: Help needed

Post by BIT0129-Tabassum Sat May 22, 2010 1:25 am

Thanks Very Happy
BIT0129-Tabassum
BIT0129-Tabassum
Global Moderator
Global Moderator

Course(s) :
  • BIT

Blood Group : A+
Posts : 1496
Points : 2298

http://probe-tabassum.blogspot.com

Back to top Go down

User verified solution Re: Help needed

Post by BIT0122-Amit Sat May 22, 2010 1:29 am

Don't say it, press it.
And change the topic title icon please Wink
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

User verified solution Re: Help needed

Post by BIT0129-Tabassum Sat May 22, 2010 1:34 am

yeah! I was going to press after giving thanks Smile and...hmm..I will change it. Very Happy
BIT0129-Tabassum
BIT0129-Tabassum
Global Moderator
Global Moderator

Course(s) :
  • BIT

Blood Group : A+
Posts : 1496
Points : 2298

http://probe-tabassum.blogspot.com

Back to top Go down

User verified solution Re: Help needed

Post by BIT0122-Amit Sat May 22, 2010 1:36 am

topic locked then Razz as it is solved now.
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

User verified solution Re: Help needed

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum