Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > beginner c questions

Reply
Thread Tools

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
constant, and a hexadecimal constant.
a) 1,234
b) 2
c) 8
d) 16
e) 1,024

Thanks in advance.

 
Reply With Quote
 
 
 
 
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
answers on a silver platter.

HOWEVER:

If you post your best attempts at your answers (better,
including your reasoning behind each), many of us will
jump in with corrections, hints, and guidance.

You do have a textbook, right?

-Mike


 
Reply With Quote
 
 
 
 
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.

 
Reply With Quote
 
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)
Hexadecimal constant:
0x2a6 (same value)

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

--
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.
 
Reply With Quote
 
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.

In either case, what does your books say about expressing
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
terms appear in its index and/or table of contents.
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


 
Reply With Quote
 
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

> Thanks in advance.


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


 
Reply With Quote
 
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?

 
Reply With Quote
 
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.

Read your book. You need to express these constants
in C, not English. Read your book. It's in there.
Really. (Unless it's a very very poor book). Which
book is it, btw?

-Mike


 
Reply With Quote
 
matt
Guest
Posts: n/a
 
      11-03-2005
C and UNIX: Tools for Software Design
Martin L. Barrett
Clifford H. Wagner

 
Reply With Quote
 
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginner's Beginner william nelson Ruby 7 04-11-2011 11:23 PM
beginner's questions 2 Scott Needham Wireless Networking 3 09-16-2005 11:05 PM
No Class at ALL!!! beginner/beginner question =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?= ASP .Net 7 02-03-2005 02:47 PM
Tutorial for beginner/ Tutorial voor beginner Rensjuh C++ 7 09-02-2004 12:41 AM
Re: Questions....questions....questions Patrick Michael A+ Certification 0 06-16-2004 04:53 PM



Advertisments