Chapter 6 Challenge


#1

Since I never paid much attention in Math and have nothing to compare it to, just wanted to make sure I had the fairly simple challenge in chapter 6 correct:

[code]#include <stdio.h>
#include <math.h>

int main (int argc, const char * argv[])
{

printf("the sine of 1 radian is: %.3f", sin(1));

return 0;

}[/code]

(gives an output of: the sine of 1 radian is: 0.841)


#2

I checked the answer on google calculator and it returns 0.841 if thats any help.


#3

In the same boat here as finding the sine of a radian isn’t something that comes naturally.

I came to the same solution as you. :smiley:


#4

Good to hear, and it does appear the result should be 0.841 and that’s what the output is. Thanks!


#5

i don’t even know what a radian was, i still dont really know what it is, I’m very weak at math.

is math a necessity for programming? I’ve been told no, but i was a f*** up in high school so the most i got up to was the 1st half of geometry


#6

[quote=“LooN3y”]i don’t even know what a radian was, i still dont really know what it is, I’m very weak at math.

is math a necessity for programming? I’ve been told no, but i was a f*** up in high school so the most i got up to was the 1st half of geometry[/quote]

Math is everywhere, to be a good programmer you need good logical skill, and logical skill is math.


#7

maybe solution is longer, don’t know (go for shorter solution or make it easier to read?) what do you think?


#include <stdio.h>
#include <math.h>

int main (int argc, const char * argv[])
{
    float x = 1.0;
    float result = sinf(x);
    printf("The Sine of 1 is %.3f \n", result);
   
    return 0;
}

#8

Easy to read is definitely important when you’re writing code that needs to be maintained over long periods of time.

You’ll find that your standard for easy to read changes over time, however, and you’ll find yourself writing terser code the more comfortable you get with the language. The original solution is perfectly reasonable and is more typical.


#9

But having a slightly longer code right now, for a beginner, nothing to worry about, right? I like writing it out long because it makes me feel more comfortable right now.


#10

Absolutely, you should write the code as long as you need to. It’s like a student learning math: the beginning student should always write out each individual step in a process, even if a more experienced student would combine several steps.


#11

Thanks for all your help so far macintux. This site is so great.


#12

I’m having issues in Terminal with the ‘man math’ command, it’s not displaying the full manual. Just giving me the following:

math(n) Tcl Math Library math(n)


NAME
math - Tcl Math Library

SYNOPSIS
package require Tcl 8.2

   package require math  ?1.2.5?

   ::math::cov value value ?value ...?

   ::math::integrate list of xy value pairs

   ::math::fibonacci n

   ::math::max value ?value ...?

   ::math::mean value ?value ...?

   ::math::min value ?value ...?

:


How do I view the whole manual? Thanks!!


#13

If you press the space bar, it should show you the next page.


#14

codegirl, you’ll want to read the C library man page, not the Tcl page, so run this instead: man 3 math

You can use spacebar to move forward a page, b to move backwards, and q to quit.

For more sophisticated commands, you can run man less (because less is the paging command that man uses), and man man to learn more about man itself, but if this sentence doesn’t have your head spinning yet, I guarantee you the man pages will.


#15

How much info is it suppose to show? Doesn’t seem to be a lot (about three pages). Thanks for the reply!


#16

[quote=“macintux”]codegirl, you’ll want to read the C library man page, not the Tcl page, so run this instead: man 3 math

You can use spacebar to move forward a page, b to move backwards, and q to quit.

For more sophisticated commands, you can run man less (because less is the paging command that man uses), and man man to learn more about man itself, but if this sentence doesn’t have your head spinning yet, I guarantee you the man pages will.[/quote]

man 3 math didn’t work, received this: No entry for math in section 3 of the manual


#17

Fascinating. A UNIX system without a C math library man page is an odd concept.

You can read it here: developer.apple.com/library/ios … ath.3.html


#18

[quote=“macintux”]Fascinating. A UNIX system without a C math library man page is an odd concept.

You can read it here: developer.apple.com/library/ios … ath.3.html[/quote]

Thank you! man math is on my desktop mac, but why the heck is it missing from my MacBookAir? (Summer 2011 edition, running 10.7.3, same as the desktop machine.) Why would the documentation be missing and does anyone know how I can get it back on the MBA?

Thanks!


#19

I messed around and came up with this. I like the shorter code, but i agree with macintux about being comfortable, as i am new to programming. Does this look acceptable?

#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[])
{
    double x = sin(1);
    printf("The sine of 1 radian is %.3f\n", x);
    
    
    return 0;
}

#20

One thing

I never really got into programming but I had to take a class in college before I cared if I passed but… one thing that the teacher made us do that I liked becuase when I had to go back on older programs he had us write.

//Start my Code

//What I’m trying to do with this code segment.
code

//End my Code