I know that to you can represent 1.425 by 1425e-3. Is that correct?
So if i want to do the inverse of a number (assuming X), then X e-1 is the reciprocal of X. Is that correct or i cannot use variables in such a way?
I know that to you can represent 1.425 by 1425e-3. Is that correct?
So if i want to do the inverse of a number (assuming X), then X e-1 is the reciprocal of X. Is that correct or i cannot use variables in such a way?
the reciprocal of X is 1/X ... Just like in math.
How do i use that to calculate in C ? do i just write 1/X ?
Did you try any of those? Which ones compiled? Which ones didn't? Which ones gave the output you expected? Which ones didn't?
You'll learn a lot more by Googling around, reading some tutorials and textbooks, and experimenting with little test programs than you ever will by coming here for quickie answers from us. Honestly, I don't know the answer off hand, but I think that using e-3 to signify * 10^-3 is only valid for floating point literals. You would have to look at the C standard to find out for sure.
Here is what i attempted. I was following some slides describing selection and loops.
Code:/* Title: Write a program to prompt the user for an integer and calculate the sum of all the integers up to and including the input value. Print out the result. Modify the previous program to use floating point arithmetic to add up the reciprocals of all the integers up to and including the input value */ #include <stdio.h> int main() { int num, count, sum, reci; printf("Input a num: "); scanf("%d", &num); sum=0; reci = 1/num ; for(count=1; count<= reci; count++) { sum=sum+count; } printf("1 + 2 ... + %d = %d,", num, sum); return 0; }
Where did that come from (and why is there so much bloody white space in there)? Why cut and paste from a lecture on selection and loops when you supposedly want to know about floating point math and notation in C? Nowhere in that example is there a floating point variable or literal. You also don't attempt to use the e notation with either variables or literals. What exactly is it you want to know? Define your problem very specifically, and post relevant code.
Line 29 i tried
but even 1/num does not work.Code:reci = num e-1 ;
No it was not a copy paste. I actually work it out in class on paper for that above question with normal numbers. So i tried modifying the program to use reciprocals instead.
what i want to know is how do i proceed to make the input numbers to be calculated as reciprocals.
And what happened? I'm guessing it didn't work, based on the following:
What doesn't work about it? Does it not compile for you? Do you get no output or the wrong output or what? I told you before, you need to be very specific about your problem. As an example: "I tried to get the reciprocal of a number by doing foo = 1 / bar;, but instead of getting .25 like I expected, I got ___. Can you please explain?" That is a clear description of a problem with a clear question, even if I left out some relevant code, like the definition of foo and bar, and where their values are set, for brevity's sake.but even 1/num does not work.
reci = 1/num; should work. Again, what is "not working" about it? Specifics please. Also, remember, you were originally talking about floating point numbers, which is what the problem seems to require, based on the comments in your code from post #5. I'll say it again: there are no floats in your code sample. Floating point and integer math work differently in computers. So where are the floats?what i want to know is how do i proceed to make the input numbers to be calculated as reciprocals.