0% found this document useful (0 votes)
10 views3 pages

Module1 Solutions

This document covers fundamental concepts in C programming for problem solving, including definitions of computers, input devices, software types, and the basic structure of a computer. It explains pseudocode, algorithms, flowcharts, and the structure of C programs, along with key programming concepts such as tokens, identifiers, constants, operators, and data types. Additionally, it provides examples of C programs for calculating areas, perimeters, and simple interest.

Uploaded by

Ngala Mac
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Module1 Solutions

This document covers fundamental concepts in C programming for problem solving, including definitions of computers, input devices, software types, and the basic structure of a computer. It explains pseudocode, algorithms, flowcharts, and the structure of C programs, along with key programming concepts such as tokens, identifiers, constants, operators, and data types. Additionally, it provides examples of C programs for calculating areas, perimeters, and simple interest.

Uploaded by

Ngala Mac
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MODULE 1 – SOLUTIONS (C Programming for Problem Solving)

1. What is a Computer? Types of Computers


A computer is an electronic device that accepts input, processes data, stores data, and produces
output.
Types: Microcomputers, Minicomputers, Mainframe computers, Supercomputers, Embedded
systems.

2. Input Devices (any two)


Input devices allow users to send data to the computer. Examples:
• Keyboard – used to enter text and commands.
• Mouse – used to point, click, and select items.

3. Software and Types


Software is a collection of programs that run on a computer.
Types: System Software, Application Software, Utility Software.

4. Basic Structure of a Computer


A computer consists of Input Unit, Output Unit, Memory Unit, Control Unit, and ALU.

5. Pseudocode
Pseudocode uses English-like statements to outline a program’s logic.
Example (sum & average of 3 numbers):
Read a, b, c
sum = a + b + c
avg = sum / 3
Print sum, avg

6. Algorithm
An algorithm is a step-by-step procedure to solve a problem.
Example (Area & Perimeter of Circle):
Step1: Read r
Step2: area = 3.14*r*r
Step3: peri = 2*3.14*r
Step4: Print area, peri

Largest of 3 numbers:
Read a, b, c
If a>b and a>c print a else if b>c print b else print c

Pseudocode vs Algorithm:
Pseudocode uses informal English; an algorithm uses formal structured steps.

7. Flowchart
A flowchart is a diagrammatic representation of logic using symbols.

Simple Interest (Flowchart explanation included):


SI = (P*T*R)/100.

8. Structure of a C Program
Header files
main()
variable declarations
statements
return 0;

9. Tokens in C
Tokens are basic building blocks. Types: Keywords, Identifiers, Constants, Strings, Operators,
Separators.

11. Identifiers
Rules: No spaces, cannot start with digit, no special symbols except _.
Validity: num2(valid), $num1(invalid), +add(invalid), a_2(valid), 199_space(invalid), _apple(valid),
#12(invalid)

13. Constants
Types: Integer constants, Floating constants, Character constants, String constants.

14. Operators
Types: Arithmetic, Relational, Logical, Assignment, Conditional, Bitwise.

15. Assignment Statement


General form: variable = expression;

16. Basic Data Types


int, float, double, char.

17. Type Conversion


Two types: Implicit (automatic), Explicit (using casting).

20. Formatted I/O


printf() – output
scanf() – input

21. C Program: Area & Perimeter of Circle


area = 3.14*r*r; peri = 2*3.14*r;

22. C Program: Print numbers 4–9 and squares.

23. Area & Perimeter of Rectangle


area = l*b; peri = 2(l+b)
24. Simple Interest Program
SI = P*T*R/100

25. Area of Triangle using Heron formula


s = (a+b+c)/2; area = sqrt(s(s-a)(s-b)(s-c))

26. Largest of 3 numbers using ternary


largest = (a>b)?(a>c?a:c):(b>c?b:c);

27. Expression Evaluation


Step-by-step evaluation provided.

28. Convert expressions


i) area = s*(s-a)*(s-b)*(s-c)
ii) x = (-b + sqrt(b*b - 4ac))

You might also like