08.01.2023 Views

Learn to Program with C_ Learn to Program using the Popular C Programming Language ( PDFDrive )

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 1 ■ Elementary Programming Concepts

b = 25;

is written as

and

set sum to a + b

is written as

sum = a + b;

One final point: you may have gathered from a previous exercise that, for this problem, the

variable sum is not really necessary. We could, for instance, have omitted sum from the program

altogether and used this:

int a, b;

a = 14;

b = 25;

printf("%d + %d = %d\n", a, b, a + b);

to give the same result since C lets us use an expression (e.g., a + b) as an argument to

printf. However, if the program were longer and we needed to use the sum in other places, it

would be wise to calculate and store the sum once (in sum, say). Whenever the sum is needed,

we use sum rather than recalculate a + b each time.

Now that we have a general idea of what is involved in writing a program, we are ready to get

down to the nitty-gritty of C programming.

Exercises 1

1. What makes it possible to do such a variety of things on a computer?

2. Computers can execute instructions written in what language?

3. Give two advantages of assembly language over machine language.

4. Give two advantages of a high-level language over assembly language.

5. Describe two main tasks performed by a compiler.

6. Describe the steps required to solve a problem on a computer.

7. Distinguish between an algorithm and a program.

8. Programming instructions fall into three main categories; what are they?

9. Distinguish between a syntax error and a logic error.

10. What is meant by “debugging a program”?

20

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!