beginner c questions

R

Randy Howard

matt wrote
(in article
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

My daughter is currently doing this sort of work in elementary
school. I can't imagine a college instructor being able to
stump a student on something this easy.
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 is slightly more difficult, but certainly something that
almost any "scientific" calculator can do on your behalf. Jeez,
this is trivial. If you can't answer these, change your major
before you fill your transcript with a semester's worth of F's.
 
P

pete

Randy said:
matt wrote
(in article


My daughter is currently doing this sort of work in elementary
school. I can't imagine a college instructor being able to
stump a student on something this easy.


This is slightly more difficult, but certainly something that
almost any "scientific" calculator can do on your behalf. Jeez,
this is trivial. If you can't answer these, change your major
before you fill your transcript with a semester's worth of F's.

On 2 November Martin Ambuhl posted a printf solution,
which corresponded to my initial take on the problem,
that it was supposed to be a printf exercise.

To me, it looks like a problem that belongs
after an introduction to format specifiers.
 
K

Keith Thompson

pete said:
Randy said:
matt wrote
(in article
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 [snip]
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 is slightly more difficult, but certainly something that
almost any "scientific" calculator can do on your behalf. Jeez,
this is trivial. If you can't answer these, change your major
before you fill your transcript with a semester's worth of F's.

On 2 November Martin Ambuhl posted a printf solution,
which corresponded to my initial take on the problem,
that it was supposed to be a printf exercise.

To me, it looks like a problem that belongs
after an introduction to format specifiers.

I don't think so. The question is about numeric literals that might
appear in a C program, not necessarily about the output produced by
printf(). It happens that printf's numeric output usually (always?)
looks like a valid numeric literal, but the questions can be answered
with no knowledge of printf formats. (printf can be used as a tool to
find the answers, but it's hardly necessary.)
 
M

matt

You must not have read through the entire post so I wont hold it
against you. I am not a college student, this questions are not for a
class. I just needed to brush up on trivial math I have not use since
school. Must of the others who replied actually helped point me in the
right direction. As for you, why do you feel the need to compare me
with your daughter?
 
D

Dennis Willson

matt said:
You must not have read through the entire post so I wont hold it
against you. I am not a college student, this questions are not for a
class. I just needed to brush up on trivial math I have not use since
school. Must of the others who replied actually helped point me in the
right direction. As for you, why do you feel the need to compare me
with your daughter?

Gee, when I read your original post, it looks to me like your asking for help in the coding not the math. Yet his post looks to me
like he thinks you're having trouble with the math. Big difference, when you don't know the programming language something that can
easily be done on a scientific calculator isn't always easy to do in code.

Some people like to jab and stroke their ego rather than actually help, or keep their fingers off the keyboard.

 
S

Sandeep

Dennis said:
Big difference, when you don't know the programming language something that can
easily be done on a scientific calculator isn't always easy to do in code.

Coding is one thing, but if someone does not even know how to convert
it using a scientific calculator , I am sure he/she will not be able to
code it.

Some people like to jab and stroke their ego rather than actually help, or keep their fingers >off the keyboard.

You did no better to help :)
 
D

Dominic Shields

I actually have Kernighan and Ritchie, "The C Programming Language"
Second Edition. I started with it but I felt it was asking me to write
c without teaching it first.

When I started with C about 12 years ago I had a copy of that book and
found that for me it was
"Teach yourself C if you are already an expert in C"

I bought "Teach Yourself C" by Herbert Schildt, then "C, The Complete
Reference" by the same author, worked for me.

Naturally, everyone's learning styles differ, I had been a Cobol
programmer for some time, not sure if that helped particularly }:)
 
M

Mabden

This is a book that can be re-read many times. You must study the code
examples and understand them before reading the following explanation.
Also, the code itself provides example of a certain "style" of writing
code. It is a subtle and complex book, but it is the finest example of a
textbook I have ever learned from. It does not try to over-explain every
line like the Wrox books, it just gives subtle hints on how to do C.
BTW, look at the size of the book versus the other "tutorials". It is
small, subtle, concise; the exact correct book to describe C.

I remember picking up the first version of K&R, back when I knew BASIC
and FORTRAN from school only - no practical experience. I found it
really hard to get through and when I got to chapter 6 (pointers) I gave
up. I then learned Pascal and Assembler. Assembler taught me how memory
and registers work, and Pascal had one kind of pointer, a "by reference"
thing. Even then I found pointers in C to be something hard to learn.
Hell, we're still talking about page 102 and null pointers today.

So don't feel too bad. Also, realize that you can read past the parts
you don't understand and read about another subject. Write code, write
code, write code.
When I started with C about 12 years ago I had a copy of that book and
found that for me it was
"Teach yourself C if you are already an expert in C"

I bought "Teach Yourself C" by Herbert Schildt, then "C, The Complete
Reference" by the same author, worked for me.

I don't think you should be saying that name 'round here... ;-(
Naturally, everyone's learning styles differ, I had been a Cobol
programmer for some time, not sure if that helped particularly }:)

Well, BASIC and FORTRAN certainly didn't help much... ;-)
 
K

Keith Thompson

Dominic Shields said:
When I started with C about 12 years ago I had a copy of that book and
found that for me it was
"Teach yourself C if you are already an expert in C"

I bought "Teach Yourself C" by Herbert Schildt, then "C, The Complete
Reference" by the same author, worked for me.

Herbert Schildt is a skilled writer of very poor books, full of
dangerous misinformation. If your knowledge of C depends on his
books, it's likely you've picked up some incorrect ideas, particularly
in understanding the difference between portable C and system-specific
features.

Some years ago, he wrote a book consisting of the 1990 ISO C standard
with annotations. See <http://www.lysator.liu.se/c/schildt.html> for
a review. Some of his other books may be marginally better; see
<http://www.accu.org/bookreviews/public/reviews/c/c002173.htm> for a
review of "C, The Complete Reference".
 
D

Dominic Shields

Herbert Schildt is a skilled writer of very poor books, full of
dangerous misinformation. If your knowledge of C depends on his
books, it's likely you've picked up some incorrect ideas, particularly
in understanding the difference between portable C and system-specific
features.

Well in a way portable C wasn't really on the cards anyway as a lot of
the C I first wrote was what Ingres called ESQL/C but I think I
appreciated right away that the books seemed to refer to C in a DOS
environment rather than things that would work in Unix.
 
M

Mark McIntyre

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.

I presume the exercise is to write a C programme to print each of the
numbers in two different formats.

We won't do your exercise for you, but read up on the printf()
function and its format string. Then post your best try at the code.
 
D

Dave Thompson

I don't think so. The question is about numeric literals that might
appear in a C program, not necessarily about the output produced by
printf(). It happens that printf's numeric output usually (always?)
looks like a valid numeric literal, but the questions can be answered

Not if %0Nd or %.Nd (or i) or u forces leading zero(s) on a value
containg a digit > 7, and for any value > 7 it may look valid but have
the wrong value; %q without # on > 7 looks like a decimal literal but
has the wrong value; %x or X without # > 9 either a wrong value
decimal or non-valid.

Any integer format with .0 on 0 produces an empty string (no token).

Any floating conversion on an infinity or qNaN produces a value not
valid as a literal, but valid as *scanf or strto*/ato* input.

And of course any numeric output that would be valid by itself could
be run together with pp-number character(s), but I assume that's not
what you meant.
with no knowledge of printf formats. (printf can be used as a tool to
find the answers, but it's hardly necessary.)

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top