Velocity Reviews > beginner c questions

# beginner c questions

matt
Guest
Posts: n/a

 11-03-2005
I new to programming and have started with c. I am stuck on 2 questions
and cannot move forward, any help would be greatly appreciated.

Question 1: Express each number as a floating-point constant using both
regular decimal notation and exponential notation.
a) 1,234
b) 1,234.5
c) 0.1234
d) 1.234 x 10 to the second power

Question 2: Express each number as an integer constant, an octal
a) 1,234
b) 2
c) 8
d) 16
e) 1,024

Mike Wahler
Guest
Posts: n/a

 11-03-2005

"matt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>I new to programming and have started with c. I am stuck on 2 questions
> and cannot move forward, any help would be greatly appreciated.
>
> Question 1: Express each number as a floating-point constant using both
> regular decimal notation and exponential notation.
> a) 1,234
> b) 1,234.5
> c) 0.1234
> d) 1.234 x 10 to the second power
>
> Question 2: Express each number as an integer constant, an octal
> constant, and a hexadecimal constant.
> a) 1,234
> b) 2
> c) 8
> d) 16
> e) 1,024

This looks too much like a verbatim homework assignment,
that I seriously doubt anyone will simply provide the

HOWEVER:

including your reasoning behind each), many of us will
jump in with corrections, hints, and guidance.

You do have a textbook, right?

-Mike

matt
Guest
Posts: n/a

 11-03-2005
Not a text book, just one from amazon supposed to be for beginners. I
am not attending a class, this is not homework. I just need a push in
the right direction, something to get started with and work backwards
from that point.

Keith Thompson
Guest
Posts: n/a

 11-03-2005
"matt" <(E-Mail Removed)> writes:
> I new to programming and have started with c. I am stuck on 2 questions
> and cannot move forward, any help would be greatly appreciated.
>
> Question 1: Express each number as a floating-point constant using both
> regular decimal notation and exponential notation.
> a) 1,234
> b) 1,234.5
> c) 0.1234
> d) 1.234 x 10 to the second power
>
> Question 2: Express each number as an integer constant, an octal
> constant, and a hexadecimal constant.
> a) 1,234
> b) 2
> c) 8
> d) 16
> e) 1,024

These are easy questions; what difficulty are you having with them?

Your C textbook should have a section on the various forms of numeric
literals, including explanations of what they all mean.

To get you started, here are some examples of each form:

Floating-point constant in regular decimal notation:
345.6
Floating-point constant in exponential notation:
3.456e2 (same value)

Integer constant (presumably this means decimal):
678
Octal constant:
01246 (same value)
0x2a6 (same value)

We're glad to help out, but we're not just going to give you the

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Mike Wahler
Guest
Posts: n/a

 11-03-2005

"matt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> Not a text book, just one from amazon supposed to be for beginners.

If you tell us which book and author, we can help assess
whether it's a quality book. Be warned, there are far
more absoutely incorrect books on C than there are correct
ones.

constant values? Every textbook I've seen (good or bad)
that has such exercises precedes them with material necessary
to complete them.

> I
> am not attending a class, this is not homework.

OK I'll just have to take your word for that. But
I'm still not going to provide the answers. (Nor
any help until I see evidence that you've actually
tried to work out solutions yourself).

>I just need a push in
> the right direction,

OK here's a 'push': Look up 'constant', or 'numeric
constant' in your book. I suspect those or similar
Also look for other terms which appear in the exercise
such as 'decimal', 'octal', 'floating point' etc.

> something to get started with and work backwards
> from that point.

Virtually every (especially beginner) textbook I've ever
read was the most useful when starting at the beginning
and working *forward*. Start on page 1.

-Mike

Martin Ambuhl
Guest
Posts: n/a

 11-03-2005
matt wrote:
> I new to programming and have started with c. I am stuck on 2 questions
> and cannot move forward, any help would be greatly appreciated.
>
> Question 1: Express each number as a floating-point constant using both
> regular decimal notation and exponential notation.
> a) 1,234
> b) 1,234.5
> c) 0.1234
> d) 1.234 x 10 to the second power
>
> Question 2: Express each number as an integer constant, an octal
> constant, and a hexadecimal constant.
> a) 1,234
> b) 2
> c) 8
> d) 16
> e) 1,024

#include <stdio.h>

inline void Q1(double x)
{
printf("fixed: %f; exponential: %e\n", x, x);
}
inline void Q2(unsigned x)
{
printf("decimal: %d; octal: %#o; hex: %#x\n", x, x, x);
}
int main(void)
{
Q1(1234);
Q1(1234.5);
Q1(0.1234);
Q1(1.234e2);
Q2(1234);
Q2(2);
Q2(;
Q2(16);
Q2(1024);
return 0;
}

fixed: 1234.000000; exponential: 1.234000e+03
fixed: 1234.500000; exponential: 1.234500e+03
fixed: 0.123400; exponential: 1.234000e-01
fixed: 123.400000; exponential: 1.234000e+02
decimal: 1234; octal: 02322; hex: 0x4d2
decimal: 2; octal: 02; hex: 0x2
decimal: 8; octal: 010; hex: 0x8
decimal: 16; octal: 020; hex: 0x10
decimal: 1024; octal: 02000; hex: 0x400

Save your bill collector cant for your job as a bill collector. Bite me.

matt
Guest
Posts: n/a

 11-03-2005
So for the first question:

a)1.234 x 10 to the 3rd
b)1.2345 x 10 to the 3rd
c)?
d)123.4

As far as octal and hexadecimal im definitly lost, is there a formula?

Mike Wahler
Guest
Posts: n/a

 11-03-2005

"matt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
> So for the first question:
>
> a)1.234 x 10 to the 3rd
> b)1.2345 x 10 to the 3rd
> c)?
> d)123.4
>
> As far as octal and hexadecimal im definitly lost, is there a formula?

No. The exercise is about syntax.

Really. (Unless it's a very very poor book). Which
book is it, btw?

-Mike

matt
Guest
Posts: n/a

 11-03-2005
C and UNIX: Tools for Software Design
Martin L. Barrett
Clifford H. Wagner

matt
Guest
Posts: n/a

 11-03-2005
If I cant even express it in english, no way I can do it in any other
language. Maybe I wasnt clear on what I was asking in the first place
or maybe comp.lang.c is the wrong place to ask such questions.