Problem Solving and Programming in C - Notes
UNIT I – Problem Solving Concepts (CO1, CO2)
Problem: A task to be performed or a question to be answered.
Problem Instance: A specific input or case of a problem.
Generalization & Special Cases: Broader and restricted forms of a problem.
Types of Computational Problems: Decision, Optimization, Enumeration.
Algorithm: Step-by-step procedure with finiteness, definiteness, and effectiveness.
Efficiency: Measured by time and space complexity.
Problem Solving Steps: Understand → Plan → Execute → Review.
Data Representation: Efficient data structures like arrays and lists.
Pre and Post Conditions: True before and after program execution.
UNIT II – Structured Programming and C Basics (CO2, CO3, CO4)
Structured Programming: Uses sequence, selection, and repetition constructs.
Sequence: Executed one after another.
Selection: Conditional execution using if, if-else, switch.
Repetition: Loops - for, while, do-while.
Pseudocode and Flowcharts: Tools for algorithm design.
C Language: Developed by Dennis Ritchie (1972), typed and structured.
I/O: scanf() for input, printf() for output.
Operators: Arithmetic (+, -, *), Relational (==, !=), Logical (&&, ||).
Good Coding Practices: Indentation, comments, meaningful names.
UNIT III – Iteration and Nested Loops (CO2, CO3, CO4)
Iteration: Repeated execution using loops.
Nested Loops: Loops inside loops for patterns.
Examples: Fibonacci series, arithmetic and geometric progressions.
Taylor Series: Approximation for sin(x), cos(x), π.
UNIT IV – Numerical Problems and C Constructs (CO2, CO3, CO4)
Number Problems: Palindrome, Prime, Armstrong, Perfect, Factorial.
Digit Extraction: Using % and / operators.
Base Conversion: Binary, Decimal, Octal, Hexadecimal.
Statistics: Max, Min, Average using Sentinel-Controlled Loops.
C Constructs: else-if ladder, switch-case, break, continue, ++ and -- operators.
Example Program: Sentinel-Controlled Repetition
#include <stdio.h>
int main() {
int marks, count=0, sum=0, max=0;
printf("Enter marks (-1 to stop): ");
while(1){
scanf("%d", &marks;);
if(marks==-1) break;
if(marks<0){ printf("INVALID INPUT\n"); continue; }
sum+=marks; if(marks>max) max=marks; count++;
}
if(count==0) printf("NO DATA\n");
else printf("Max=%d, Average=%.2f\n", max, (float)sum/count);
return 0;
}
Summary: Problem solving involves understanding, planning, executing, and reviewing. Algorithms
must be correct, efficient, and structured. Loops and conditions form the core of C programming.