0% found this document useful (0 votes)
251 views

CAPE C Programming

The document discusses problem solving with computers in Computer Science Unit 1, defining problem solving, algorithms, and their role in the problem solving process. It explains that algorithms are sets of specific steps to solve a problem and provides examples of algorithms using sequencing, selection, iteration, and assignment statements. The document also includes an activity asking the reader to write a program in C that takes two integer inputs and prints their average.

Uploaded by

Rafena17
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
251 views

CAPE C Programming

The document discusses problem solving with computers in Computer Science Unit 1, defining problem solving, algorithms, and their role in the problem solving process. It explains that algorithms are sets of specific steps to solve a problem and provides examples of algorithms using sequencing, selection, iteration, and assignment statements. The document also includes an activity asking the reader to write a program in C that takes two integer inputs and prints their average.

Uploaded by

Rafena17
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CAPE Computer Science Unit I

MODULE 2: PROBLEM-SOLVING WITH COMPUTERS

 Definition of problem-solving.
 Problem definition; problem analysis; identify and evaluate possible solutions; select and
justify the optimal solutions; implementation and review.
 Definition; algorithm as a problem-solving strategy; its role and importance in the problem-
solving process.
 A general solution to the problem, clearly defined and unambiguous steps, finite number of
steps, and flow of control from one process to another.
 Inclusion of narrative, flow charts and pseudocode.
 Input and output statements.
Control Structures:
Sequencing; Selection; Iteration or repetition (bounded, for example, fixed number of
iterations and unbounded, for example, sentinel control); Assignment statement.
 Determination of output and correctness of a given algorithm (the algorithm may be
expressed in narrative, flow charts or pseudocode).
 Determination of whether an algorithm achieves its stated objective and if not provision of
the correct algorithm.
 Algorithms as logically sequenced instructions.

What is problem-solving?

Solving problems is the core of Computer Science. Programmers must first understand how
humans would solve a problem, and then translate this “algorithm” into something the computer
can do.

Definition

An algorithm is a set of specific steps to solve a problem. For example, the recipe for baking a
cake provides a set of specific instructions to solve the problem “How do I bake a cake?”.

Good programmers must be able to define the steps necessary for solving problems.
Unfortunately, a computer knows a restricted and limited set of possible steps. For example, a
computer can add two numbers, but finding the average of two numbers is beyond the basic
capabilities of a computer. We, therefore, must devise a solution that uses the capabilities of the
computer as follows:

1. First: Add the two numbers and save the result in a variable
2. Then: divide this new number by the number 2, and save the result in a variable
3. Finally: provide this number to the rest of the program (or print it for the user)

Activity

Write a program in C that takes two integer inputs and prints the average.

Programming in C
CAPE Computer Science Unit I

1. #include is known as a preprocessor directive. It tells the compiler to “include” text from
another file into your source code.
2. The whole statement #include <stdio.h> tells the compiler to take text from the file
STDIO.H and stick it into your source code before the source code is compiled. The
STDIO.H file itself contains information about the standard Input/Output functions required
by most C programs. The H means “header.”
3. int main does two things. First, the int identifies the function main as an integer
function, meaning that main() must return an integer value when it’s done. Second, that
line names the function main, which also identifies the first and primary function inside the
program.
4. Two empty parentheses follow the function name, but may sometimes include other items.
5. All functions in C have their contents encased by curly braces. So, the function name comes
first (main in Item 3), and then its contents - or the machine that performs the function's job
- is hugged by the curly braces.
6. printf is the name of a C language function, so it should be written as printf(). Its job
is to display information on the screen.
7. Like all C language functions, printf() has a set of parentheses. In the parentheses, you
find text, or a "string" of characters. Everything between the double quote characters (") is
part of printf's text string.
8. An interesting part of the text string is d\n. That's the backslash character and a little n.
What it represents is the character produced by pressing the Enter key, called a newline in C.
9. The printf line, or statement, ends with a semicolon. The semicolon is C language
punctuation - like a period in English. The semicolon tells the C compiler where one
statement ends and another begins. Note that all statements require semicolons in C, even if
only one statement is in a program or function.
10. The second statement in GOODBYE.C is the return command. This command sends the
value 0 (zero) back to the operating system when the main() function is done. Returning a
CAPE Computer Science Unit I

value is required as part of the main() function. Note that even though this command is the
last one in the program, this statement ends in a semicolon.

You might also like