Help needed
2 posters
IITDU Forum :: Academics (BIT) :: Semester 3 :: MATH 304
Page 1 of 1
Help needed
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
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
Re: Help needed
try changing this part
and from
to this
edit: Oops... i just noticed. you need to initialize value of key as 1 or else it will not even enter in the loop.!!
- Code:
while(key==0){
for(i=0;i<n;i++)
{
- 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.!!
Similar topics
» Opinion needed : which one is looking better ?
» JSDK needed
» Opinion Needed: No Negative Voting
» Java Help needed: Problem with using graphics
» Feedback needed about UVa Rank List from all batches
» JSDK needed
» Opinion Needed: No Negative Voting
» Java Help needed: Problem with using graphics
» Feedback needed about UVa Rank List from all batches
IITDU Forum :: Academics (BIT) :: Semester 3 :: MATH 304
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford