Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan

Programming in C, 3rd ed. (Stephen Kochan) => Answers to Odd-Numbered Exercises => : ZophtX January 06, 2010, 08:50:46 AM



: is this rite? ( excursive 2)
: ZophtX January 06, 2010, 08:50:46 AM
3.31 * 10^-8 * 2.01 * 10^-7 / 7.16 * 10^-6 * 2.01 * 10^-8
one. im not sure if the answer to this problem is rite when i do the code.

: (Objective-C)
#include <stdio.h>

int main(){
double ten8, ten7, ten6;
float num3, num2, num7;
long double div1, div2, answer;

ten8 = 0.00000001; // 10^-8
ten7 = 0.0000001;  // 10^-7
ten6 = 0.000001;   // 10^-6

num7 = 7.16;
num3 = 3.31;
num2 = 2.01;

div1 = num3 * ten8 * num2 * ten7;// 3.31 * 10^-8 * 2.01 * 10^-7
div2 = num7 * ten6 * num2 * ten8;// 7.16 * 10^6 * 2.01 * 10^8

answer = div1 / div2;// 3.31 * 10^-8 * 2.01 * 10^-7 / 7.16 * 10^-6 * 2.01 * 10^-8

printf("3.31 * 10^-8 * 2.01 * 10^-7 / 7.16 * 10^-6 * 2.01 * 10^-8 \n");
printf("equals\n");
printf("%Lf \n",answer);
        return 0;
}

just this code give the right answer???


: Re: is this rite? ( excursive 2)
: skochan January 06, 2010, 01:22:38 PM
I was looking for you to use scientific notation for the numbers that are raised to powers of 10.  For example, 7.16 x 10-6 is expressed as 7.16e-6 in scientific notation.

Cheers,


Steve Kochan


: Re: is this rite? ( excursive 2)
: ZophtX January 07, 2010, 01:41:26 PM
 :D ;D :D ;D :)

i have not done mathematics for quite some time so im actally a bit rusty.

the 7.16e-6 make alot more snice and i see it make the code mre shorter too.
thinks for the reminder.

your C and obj-c books are great. i treid a couple ohter and i had a hard time learning. you go step by step
thanks


back to the subject.. i post the redo of the code after i  fix it. 


: Re: is this rite? ( excursive 2)
: ZophtX February 02, 2010, 07:19:12 AM
: (Objective-C)
#include <stdio.h>

int main(){
double ten8, ten7, ten6;
float num3, num2, num7;
long double div1, div2, answer;

ten8 = 10e-8; // 10^-8
ten7 = 10e-7;  // 10^-7
ten6 = 10e-6;   // 10^-6

num7 = 7.16;
num3 = 3.31;
num2 = 2.01;

div1 = num3 * ten8 * num2 * ten7;// 3.31 * 10^-8 * 2.01 * 10^-7
div2 = num7 * ten6 * num2 * ten8;// 7.16 * 10^6 * 2.01 * 10^8

answer = div1 / div2;// 3.31 * 10^-8 * 2.01 * 10^-7 / 7.16 * 10^-6 * 2.01 * 10^-8

printf("3.31 * 10^-8 * 2.01 * 10^-7 / 7.16 * 10^-6 * 2.01 * 10^-8 \n");
printf("equals\n");
printf("%Lf \n",answer);

return 0;

}

Here i fixed it. it give me the same result as the code before this.
so i believe i have the right result.


: Re: is this rite? ( excursive 2)
: skochan February 02, 2010, 07:58:21 AM
Okay, that works, but remember you can more easily write a line like this:

: (Objective-C)
  div1 = num3 * ten8 * num2 * ten7;// 3.31 * 10^-8 * 2.01 * 10^-7

this way:

: (Objective-C)
  div1 = 3.31e-8 * 2.01e-7;   // 3.31 * 10^-8 * 2.01 * 10^-7

Cheers,

Steve


Sorry, the copyright must be in the template.
Please notify this forum's administrator that this site is missing the copyright message for SMF so they can rectify the situation. Display of copyright is a legal requirement. For more information on this please visit the Simple Machines website.