15,039,359 members
See more:
( Consider the function
f(X)=1/X-D
for which the newton-Raphson iteration gives
Xi+1=Xi-(f(Xi)/f'(Xi))=Xi-((1/Xi-D)/(-1/Xi ^2))=Xi+Xi(1-DXi)=Xi(2-DXi)
Which can be calculated from Xi using only multiplication ans subtraction , or using two fused multiply-addition. Can you expect what it does and what all care you are required to take while implementing it and can you write a C code to compute it. )

my ans:
#include<stdio.h>
main()
{
float X[15],X1[15]; //i took X for Xi and X1 for Xi+1;
int D;
printf("enter the value for X[i]:");
scanf("%f",&X[15]);
printf("\nenter the value of D:");
scanf("%d",&D);
X1[15]=X[15]*(2-(D*X[15]));
printf("X[i+1]=%f \n",X1[15]);
}

Am some what beginner at c programming.Thank you.
Posted

## Solution 1

Do what we all have to do when we write code: test it and see.
Compile the code, run the coffee, and work out what results you should get - Wolfram Alpha[^] may help - and then see what your code produces. If it's the same for all values you try, then it probably works.

If it doesn't...
Member 10791767 5-May-14 2:51am

@originalgriff sir can you tell me is my answer is apt for the given question? because my code seems to be very small.
OriginalGriff 5-May-14 6:53am

Have you tried it?
Member 10791767 5-May-14 10:39am

@originalgriff. Yes i did the compilation and I am getting the output without any error. But what I did in the code is just implemented the equation(got the input as D and Xi and did the multiplications and subtraction). My code is smaller than the question. So, i doubt whether my output and code is a correct answer to the given question? Is what i did is what they are expecting?
OriginalGriff 5-May-14 10:50am

"Compilation" != "Output"

All compilation means is that the program *can* be converted to an executable program: it doesn't mean that the program executes without error, or that it produces the correct result (or indeed any result).
So work out what input you are going to feed it, work out what result it should give, and try it...
Member 10791767 5-May-14 23:37pm

@originalgriff I gave the input as D:1 Xi:1. so, Xi+1=1*(2-(1*1))=1.0000 is my output. Is that the output they are expecting because i cannot understand the question much clearly. If I have wrongly understood, can you help me to understand the question clearly?
OriginalGriff 6-May-14 4:18am

My friend, I don't want to seem rude, but I have to be blunt here: The idea of interview questions is not to annoy you, but to weed out those who can't do the job; so that the interviewer (who is a very busy man) doesn't have to spend time on actual interviews which people who aren't going to be suitable.
And if you think that throwing one simple value at that is "testing" it, then you can't do the job - you just aren't ready yet. So me helping you to get through this stage is unhelpful to three people: the interviewer who will realise very quickly that you didn't write the code; the person whose interview place you took because they probably could do the job; and you - because it gets your hopes up only to feel humiliated and discouraged because the interview is cut short and you have wasted your time. That it also wastes my time is irrelevant here.

Go back to the beginning, start again with learning to code and try to understand what processes are involved - because at the moment it's pretty clear that you have picked up some of the mechanics of "throwing code together" but glossed over the parts that actually matter.

Sorry, but it does have to be said: at the moment, you are wasting your time trying to pass an interview for a computer related job.
Member 10791767 6-May-14 23:50pm

I actually didn't got through that interview and I am preparing for my next in another company, I thought if I get to know how to solve this kind of questions it may be helpful for me in the upcoming interviews. @originalgriff Is your comment mean that my answer is a complete mistake for the given question? I can able to code if i can understand what they are expecting.AND I AM HIGHLIGHTING THAT "i am not going to copy the codes" i want to understand the concept and understand what they are expecting".