Problem solving is a systematic and scientific process used to find a solution to a given problem using logical reasoning and computational methods.
Conclusion: Problem solving requires logical thinking, planning, designing, coding, and testing to obtain correct and efficient results.
A set of sequential steps usually written in Ordinary Language to solve a given problem is called Algorithm.
An algorithm is “a complete, unambiguous, finite number of logical steps for solving a specific problem.”
Algorithm to find sum of two numbers:
A flowchart is a graphical representation of an algorithm using standardized symbols.
Aflowchart is a diagram made up of boxes, diamonds and other shapes, connected by arrows. Each shape represents a step of the solution process and the arrow represents the order or link among the steps
Advantages
| Symbol | Name | Purpose |
|---|---|---|
Oval |
Start/Stop (Terminator) | Indicates beginning or end of program. |
Parallelogram |
Input/Output | Used for reading or displaying data. |
Rectangle |
Process | Represents calculations or processing steps. |
Diamond |
Decision | Represents conditional branching (Yes/No). |
Arrow |
Flow Line | Shows direction of control flow. |
Circle with Arrow |
On-page Connector | Connects different sections on same page. |
Square Pentagon |
Off-page Connector | Connects flow across pages. |
Advantages:
A C program is organized into different sections to ensure clarity, modularity, and systematic execution. Each section has a specific purpose in the compilation and execution process.
Contains comments describing the program. Comments are ignored by the compiler.
Example:
/* Program to calculate area of a circle */
// Single line comment
Includes header files using #include directive.
#include <stdio.h>
#include <math.h>
Defines symbolic constants using #define.
#define PI 3.14159
#define MAX 100
Contains global variables and function prototypes.
int count;
void display();
The entry point of every C program. Execution begins from main().
int main() {
// statements
return 0;
}
Additional functions written by the programmer to perform specific tasks.
void display() {
printf("Hello World");
}
/* Documentation Section */
#include <stdio.h> // Link Section
#define PI 3.14 // Definition Section
int count; // Global Declaration
void display(); // Function prototype
int main() // Main Function
{
display();
return 0;
}
void display() // Sub Program
{
printf("Structure of C Program");
}
Operators are symbols used to perform operations on variables and constants. They are essential in performing arithmetic calculations, comparisons, logical decisions, assignments, and type conversions in C programs.
Used to perform mathematical calculations.
int a = 10, b = 3;
int sum = a + b; // 13
int diff = a - b; // 7
int prod = a * b; // 30
int div = a / b; // 3
int rem = a % b; // 1
Used to compare two values. These operators return 1 (True) or 0 (False).
int a = 5, b = 10;
int result1 = (a < b); // 1
int result2 = (a == b); // 0
Logical operators are used to combine multiple conditions.
int a = 5, b = 10;
int result1 = (a < b && b > 5); // 1
int result2 = (a > b || b > 5); // 1
int result3 = !(a < b); // 0
Used to assign values to variables.
int a = 10;
a += 5; // a = 15
a -= 3; // a = 12
a *= 2; // a = 24
a /= 4; // a = 6
(A) Implicit Type Conversion:
Automatic conversion performed by the compiler.
int a = 5;
float b = a; // int automatically converted to float
(B) Explicit Type Conversion (Type Casting):
Manual conversion performed by the programmer.
int a = 5, b = 2;
float result = (float)a / b; // Output: 2.5
Type conversion ensures correct results, especially during division operations where integer division may truncate decimals.
PSPC – Unit 1 | Prepared by Dr.M.RajaRoy