Thread: Any idea why C is outputting these values?

  1. #1
    Registered User
    Join Date
    Feb 2015
    Posts
    1

    Any idea why C is outputting these values?

    I'm a beginner in C and can't figure out why the values for Sin_Value and Table are being calculated as so, because if i take them as number rather than an array they are calculated correctly. Any help is appreciated or any advice for future.

    My Code so far:
    Code:
    #include<stdio.h>
    #include<conio.h>
    #include<math.h>
    
    
    void main()
    {
        float Table[3][18], Sin_Value[18];
        int Degrees = 0;
        float radians;
        int i,j;
        float PI=3.14159;
    
    
        for(j=0, Degrees=0;j<=17 && Degrees <= 180; ++j, Degrees= Degrees+10)
        {
                radians= Degrees*PI/180;
                Sin_Value[j]=sin(radians);
                Sin_Value[j]= Table[0][j];
                printf("%.5f\n %.5f\n %.5f\n", radians, Sin_Value[j], Table[0][j]);
        }
        getch();
    }

  2. #2
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    693
    You haven't given Table any specific values.. you're printing random values in memory.

    Looks like you have your table assignment backwardssss
    Code:
    int get_random_number(void)
    {
       return 4; //chosen by fair dice roll.
                 //guaranteed to be random
    }

  3. #3

  4. #4
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Not in his world it doesn't. Take a look at the header files. I think conio.h kind of gives it away. Hello India! I am willing to bet the OP is using a Borland compiler.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Quote Originally Posted by AndrewHunter View Post
    Not in his world it doesn't. Take a look at the header files. I think conio.h kind of gives it away. Hello India! I am willing to bet the OP is using a Borland compiler.
    I noticed. It costs nothing to offer advice, though, whether it will or will not be taken.

    And there's a chance that someone other than the OP will see it, and learn something.

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by Matticus View Post
    I noticed. It costs nothing to offer advice, though, whether it will or will not be taken.

    And there's a chance that someone other than the OP will see it, and learn something.
    I completely agree with the advice you gave and I would have given the same advice if you hadn't already. I was more or less just making a tongue in cheek comment. No offense intended.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    No offense taken

    For some reason, I've settled into a dour way of response on this board. But don't let it fool you - sometimes I like to let my silliness come through ... i.e. "Edible data structures" presents...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 12-10-2013, 02:29 AM
  2. Replies: 13
    Last Post: 07-27-2013, 10:20 AM
  3. Replies: 2
    Last Post: 07-21-2013, 10:35 PM
  4. write() and read() int values from socket returning wrong values.
    By Premjith P S in forum Linux Programming
    Replies: 8
    Last Post: 11-29-2012, 02:59 PM
  5. Good idea, bad idea.
    By sean in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 06-15-2002, 12:26 PM

Tags for this Thread