Amazon.com Widgets is this rite? ( excursive 2)
Welcome, Guest. Please login or register.
Did you miss your activation email?
October 31, 2014, 12:15:35 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ 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
| | |-+ is this rite? ( excursive 2)
Pages: [1] Go Down
Print
Author Topic: is this rite? ( excursive 2) (Read 3176 times)
ZophtX
Newbie
*
Posts: 7






on: 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.

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???
Last Edit: January 06, 2010, 08:53:13 AM by ZophtX Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #1 on: 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
Logged
ZophtX
Newbie
*
Posts: 7






Reply #2 on: January 07, 2010, 01:41:26 PM

 Cheesy Grin Cheesy Grin Smiley

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. 
Logged
ZophtX
Newbie
*
Posts: 7






Reply #3 on: February 02, 2010, 07:19:12 AM

Code: (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.
Logged
skochan
Administrator
Hero Member
*****
Posts: 3114







Reply #4 on: February 02, 2010, 07:58:21 AM

Okay, that works, but remember you can more easily write a line like this:

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

this way:

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

Cheers,

Steve
Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.