Thread: Using E(exponential)

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    20

    Question Using E(exponential)

    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?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    the reciprocal of X is 1/X ... Just like in math.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    20
    How do i use that to calculate in C ? do i just write 1/X ?

  4. #4
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    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.

  5. #5
    Registered User
    Join Date
    Oct 2011
    Posts
    20
    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;
    
    
    
    
       }

  6. #6
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    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.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by skg29 View Post
    How do i use that to calculate in C ? do i just write 1/X ?
    Well gosh... why not give that a try and see what happens?

  8. #8
    Registered User
    Join Date
    Oct 2011
    Posts
    20
    Line 29 i tried
    Code:
    reci = num e-1 ;
    but even 1/num does not work.
    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.

  9. #9
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Quote Originally Posted by skg29 View Post
    Line 29 i tried
    Code:
    reci = num e-1 ;
    And what happened? I'm guessing it didn't work, based on the following:
    but even 1/num does not work.
    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.
    what i want to know is how do i proceed to make the input numbers to be calculated as reciprocals.
    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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Exponential Distribution
    By charlest in forum C Programming
    Replies: 1
    Last Post: 11-24-2009, 09:37 PM
  2. exponential question
    By libchk in forum C Programming
    Replies: 3
    Last Post: 11-09-2007, 04:09 AM
  3. Exponential Notation
    By Hank Diddler in forum C Programming
    Replies: 2
    Last Post: 09-15-2007, 12:34 AM
  4. exponential numbers
    By Loic in forum C++ Programming
    Replies: 4
    Last Post: 07-31-2007, 07:58 PM
  5. exponential
    By hei in forum C Programming
    Replies: 2
    Last Post: 10-10-2001, 11:46 AM