0% found this document useful (0 votes)
15 views13 pages

Problem Solving and Programming Basics

The document provides an extensive overview of programming concepts, including problem solving, algorithms, data structures, control statements, and file handling in C. It covers definitions, syntax, and examples for various programming constructs such as arrays, structures, functions, and file operations. Additionally, it includes programming exercises to reinforce the concepts discussed.

Uploaded by

priyanka.it
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)
15 views13 pages

Problem Solving and Programming Basics

The document provides an extensive overview of programming concepts, including problem solving, algorithms, data structures, control statements, and file handling in C. It covers definitions, syntax, and examples for various programming constructs such as arrays, structures, functions, and file operations. Additionally, it includes programming exercises to reinforce the concepts discussed.

Uploaded by

priyanka.it
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

Unit -01

1. What is Problem Solving?


Problem solving is the process of identifying a problem and finding a logical solution.
It involves understanding the problem clearly and breaking it into smaller parts.
Steps include analysis, designing the solution, writing code, and testing.
It helps create efficient and correct programs.

2. What is a Problem Analysis Chart?


A Problem Analysis Chart is a table used to analyze a problem before solving it.
It includes sections like Input, Output, Processing, and Formula/Conditions.
It helps the programmer clearly understand requirements.
This chart ensures the algorithm matches the problem needs.

3. What is an Algorithm?
An algorithm is a step-by-step procedure to solve a problem.
It must be clear, finite, and logically ordered.
Algorithms help convert problems into workable steps.
They form the base for writing programs and flowcharts.

4. What is a Flowchart?
A flowchart is a graphical representation of an algorithm.
It uses symbols like rectangles, diamonds, and arrows.
Flowcharts show the flow of logic visually.
They help in understanding and debugging programs.

5. What is Pseudocode?
Pseudocode is a simple, English-like description of a program.
It is not executable but looks similar to real code.
Programmers use pseudocode to plan the logic.
It is easy to read and convert into actual code.

6. What is a Program Structure?


Program structure defines the arrangement of statements in a program.
It includes input section, processing, and output statements.
A structured program is easy to read and maintain.
It improves clarity and avoids errors.

7. What is Compilation?
Compilation converts source code into machine code.
A compiler checks syntax errors during this process.
If no errors exist, an executable file is created.
Compiled programs run faster and efficiently.

8. What is Execution in programming?


Execution is running the compiled or interpreted program.
The computer follows instructions step by step.
Input is taken, processed, and output is produced.
Successful execution means the program works correctly.

9. What is Indentation?
Indentation is adding spaces at the beginning of lines.
It shows the structure and grouping of statements.
Languages like Python require indentation for blocks.
It improves readability and prevents logical errors.

10. What are Variables?


A variable is a named memory location.
Its value can change during program execution.
Variables store data like numbers or text.
They are essential for performing calculations.

11. What are Constants?


Constants are fixed values that do not change.
They are defined once and used many times.
Constants improve program stability and clarity.
Example: pi = 3.14 used in math calculations.

12. What are Reserved Words?


Reserved words are predefined keywords in a language.
They have special meaning and cannot be reused as variable names.
Examples: if, else, for, while.
They help define the structure of the program.

13. What are Arithmetic Operators?


Arithmetic operators perform mathematical operations.
They include +, –, ×, ÷, and %.
Used for calculations like addition or division.
They are commonly used in expressions.

14. What are Logical Operators?


Logical operators combine conditions and return True/False.
They include AND, OR, and NOT.
Used in decision-making statements.
Helpful when checking multiple conditions at once.

15. What is an Input/Output Function?


Input function takes data from the user.
Output function displays results on the screen.
Example: input() and print() in Python.
They help interact with the user during execution

15 marks
[Link] the steps of problem solving with a neat Problem Analysis Chart.
2. Describe Algorithm, Flowchart, and Pseudocode with advantages and examples.
3. Explain program structure, compilation process, and execution process with a diagram.
4. Discuss Interactive mode vs Script mode in Python with examples.
5. Explain data types, constants, variables, and reserved words in detail.
6. Describe Arithmetic, Relational, Logical, Bitwise, Assignment, and Conditional operators
with examples.
7. Write a detailed note on input/output functions and built-in functions in programming.
8. Explain comments, indentation, and types of errors with examples.
9. Draw and explain the different flowchart symbols with a sample flowchart.
10. Explain how an algorithm is developed from a problem statement and converted into a
program.
Unit -02
2 marks
Syntax of if statement
The if statement tests a condition and executes a block when the condition is true.
Syntax:
if (condition) {
statements;
}

2. Syntax of if-else
If-else provides two paths of execution.
Syntax:
if (condition) {
statements;
} else {
statements;
}

3. Syntax of nested if
Nested if means placing one if inside another.
Syntax:
if (condition1) {
if (condition2) {
statements;
}
}

4. Syntax of switch-case
Switch selects one case from many based on an expression.
Syntax:
switch(value) {
case 1: statements; break;
case 2: statements; break;
default: statements;
}

5. Syntax of while loop


While loop executes while the condition remains true.
Syntax:
while (condition) {
statements;
}

6. Syntax of do-while loop


Do-while executes at least once before condition checking.
Syntax:
do {
statements;
} while (condition);

7. Syntax of for loop


For loop is used for definite iteration.
Syntax:
for (initial; condition; increment) {
statements;
}

8. Syntax of nested loops


Loops inside another loop.
Syntax:
for (i=0; i<n; i++) {
for (j=0; j<m; j++) {
statements;
}
}

9. Syntax of break and continue (jump statements)


Break stops a loop; continue skips to next iteration.
Syntax:
break;
continue;

10. Syntax of goto (jump statement)


Transfers control to a labeled statement.
Syntax:
goto label;
label: statements;
11. Syntax of function declaration
Declares name, return type, and parameters.
Syntax:
return_type function_name(type1, type2);

12. Syntax of function definition


Provides function body.
Syntax:
return_type function_name(type1 a, type2 b) {
statements;
}

13. Syntax of function call


Executes or invokes the function.
Syntax:
function_name(arguments);

14. Syntax for call by value


Passes copies of values.
Syntax:
function(x);
void function(int a) { … }

15. Syntax for call by reference


Uses addresses /pointers.
Syntax:
function(&x);
void function(int *a) { … }

16. Syntax of recursive function


A recursive function is one that calls itself.
It breaks a problem into smaller sub-problems.
Syntax:
void fun() {
if(condition) return;
fun();
}

17. Syntax of global and local variables


Local inside function, global outside.
Syntax:
int g; // global
void fun() {
int x; // local
}

18. Syntax for header file inclusion


Used to access library functions.
Syntax:
#include <stdio.h>
#include <math.h>

[Link] scope of a variable.


Scope refers to the region where a variable is accessible.
Variables may have local or global scope.
Local variables exist inside a function/block.
Global variables are accessible throughout the program.

20. Define lifetime of a variable.


Lifetime refers to the duration a variable exists in memory.
Local variables exist only during function execution.
Global variables exist until the program ends.
Static variables preserve values between calls.

21. What are header files?


Header files contain predefined functions and declarations.
Common headers are stdio.h, math.h, string.h.
They are included using #include directive.
They support modular and reusable coding.

22. What is modular programming?


Modular programming divides a program into small independent functions.
Each module performs a specific task.
It improves readability and reusability.
It helps in debugging and maintenance.
15 marks
[Link] in detail the different decision-making statements in C with examples.
2. Describe and compare the looping constructs: while, do-while, and for loops with suitable
programs.
3. Discuss nested loops and jump statements in detail with examples.
4. Explain function declaration, definition, and calling with examples.
5. Differentiate call by value and call by reference with programs.
6. Write notes on recursive functions with suitable examples.
7. Explain scope and lifetime of variables in C with examples.
8. Discuss header files and modular programming in detail with advantages.
Unit -03
[Link] is a one-dimensional array?
A one-dimensional array is a linear collection of elements of the same type.
Elements are stored in continuous memory locations.
They are accessed using a single index starting from 0.
Example: int a[5];.

2. What is a multi-dimensional array?


A multi-dimensional array stores data in table-like format (rows and columns).
Common form is a 2D array represented as matrix.
Access requires multiple indices like a[i][j].
Example: int a[3][3];.

3. What is array traversal?


Traversal means visiting each element of the array one by one.
Used for displaying, searching, or modifying elements.
Usually done using loops such as for or while.
Ensures all elements are processed.

4. What is string declaration?


A string is declared as a character array ending with a null character \0.
Example: char name[20];.
It can store a sequence of characters.
Strings are handled using <string.h> functions.

5. How to take string input/output?


String input uses scanf(), gets(), or fgets().
String output uses printf() or puts().
Example: gets(str); puts(str);.
Input stops at whitespace unless using gets/fgets.

6. What are string library functions?


These are predefined functions in <string.h>.
Examples: strlen(), strcpy(), strcmp(), strcat().
Used for operations like length, copy, compare, and concatenate.
They simplify string manipulation tasks.

7. What is pointer arithmetic?


Pointer arithmetic includes operations like increment, decrement, addition, and subtraction.
Incrementing a pointer moves to the next memory location of its data type.
Example: p++ moves to next element.
Arithmetic is based on data type size.

8. How are pointers and arrays related?


Array name acts as a pointer to its first element.
a is equivalent to &a[0].
Pointers can access array elements using pointer arithmetic.
Example: *(a + i) equals a[i].

9. What is a pointer to a function?


A function pointer stores the address of a function.
It can be used to call functions indirectly.
Syntax: returnType (*ptr)(arguments);.
Useful in callback functions and event handling.

10. What is dynamic memory allocation?


Dynamic memory allocation allocates memory at runtime.
Functions used are malloc(), calloc(), realloc(), and free().
These are found in <stdlib.h>.
It helps manage memory efficiently during program execution.

[Link] Array ?
An array is a collection of elements of the same data type stored in contiguous memory
locations.
It allows multiple values to be stored under a single variable name using an index.
Arrays help in efficient data management and traversal.
Array indexing in C starts from 0.
15 marks
1. Explain one-dimensional and multi-dimensional arrays with syntax, examples, and memory
representation.
2. Discuss array operations such as traversal, insertion, deletion, search, and update with
algorithms.
3. Describe string declaration, input/output methods, and string handling functions with
examples.
4. Explain pointer arithmetic in detail with examples of operations and memory effects.
5. Discuss the relationship between pointers and arrays with diagrams and sample programs.
6. Explain pointers to functions with syntax, declaration, calling, and applications.
7. What is dynamic memory allocation? Explain malloc, calloc, realloc, and free with
illustrations.
8. Write detailed notes on multi-dimensional arrays and their applications in real-time programs.
Unit -4
. Define Structure with Syntax
A structure is a user-defined data type that groups different data types under one name.
It helps in storing related information together.
Structures are declared using the struct keyword.
Syntax:
struct struct_name {
data_type member1;
data_type member2;
};
2. What is Array of Structures?
An array of structures stores multiple structure variables in a single array.
It allows handling records like students, employees, etc.
Each element of the array is a separate structure variable.
Example:
struct student s[10];

3. Define Pointer to Structure


A pointer to a structure stores the address of a structure variable.
It is used to access structure members using the -> operator.
This helps in dynamic memory allocation of structures.
Example:
struct emp *p;

4. Define Union
A union is similar to a structure but shares the same memory location for all members.
Only one member can hold a value at a time.
It saves memory in embedded and low-level programming.
Example:
union data { int x; float y; };

5. What is Enumeration (enum)?


An enumeration is a user-defined data type with named integer constants.
It improves code readability and reduces errors.
Enum values start from 0 unless specified.
Example:
enum days {Sun, Mon, Tue};

15 Marks

1. Explain structures in C. Discuss declaration, initialization, accessing members, and


applications with examples.
2. Describe array of structures. Explain how to store and process multiple records using suitable
examples.
3. What is a pointer to a structure? Explain declaration, accessing members using arrow operator,
and usage with dynamic memory allocation.
4. Explain unions in detail. Compare structures and unions with memory diagrams and examples.
5. Write a detailed note on enumerations. Explain syntax, initialization, operations, and
advantages with examples.

Unit -05
[Link] File in C and its Syntax
A file is a storage area on disk used to save program data permanently.
C uses file handling functions to open, read, write, and close files.
A FILE pointer is used to work with files.
Syntax:
FILE *fp;

2. What is fopen()? Give Syntax.


fopen() is used to open a file in a specified mode.
It returns a pointer of type FILE.
If the file cannot be opened, it returns NULL.
Syntax:
fp = fopen("[Link]", "r");

3. Difference Between Text File and Binary File


Text files store data as human-readable characters.
Binary files store data in machine-readable 0s and 1s.
Binary files are faster and preserve exact data formats.
Text files are slower and may change formatting.

4. Define File Pointer


A file pointer stores the address of a file structure used by C.
It keeps track of the current read/write position in the file.
All file operations use this pointer.
Example:
FILE *fp;

5. What is Error Handling in File Operations?


Error handling ensures safe file access during failures.
We use conditions like if(fp == NULL) to check errors.
It prevents the program from crashing.
Example:
if(fp == NULL) printf("Error!");

6. What is fclose()?
fclose() closes an opened file in C.
It ensures data is saved properly and frees system resources.
It returns 0 on success and EOF on failure.
Example:
fclose(fp);

7. What is a User-Defined Header File?


It is a header file created by the programmer.
It contains custom functions and declarations.
It is included using double quotes, not angle brackets.
Example:
#include "myfile.h"

8. Name Any Two Standard Library Header Files


Standard headers provide predefined functions.
Examples include stdio.h, stdlib.h, string.h, and math.h.
Each library contains a set of built-in useful functions.
They are included using #include.

15 marks
Explain file operations in C. Discuss file opening, reading, writing, closing with examples.
2. Compare Text and Binary files. Explain advantages, disadvantages, and usage with program
examples.
3. Describe file pointers in detail. Explain fseek(), ftell(), and rewind() with examples.
4. Explain error handling in file operations. Discuss error checking methods and file validation
methods.
5. Explain standard libraries stdio.h, stdlib.h, string.h, math.h and the functions provided by
each.
6. Explain how to create and use user-defined header files and libraries in C with examples.

UNIT 1 – Basic Programs


1. Write a C program to calculate and display the electricity bill using conditions for
different tariff slabs.
(Use if / else or switch)
2. Write a program to find the roots of a quadratic equation using the formula method.
(Use decision-making + math functions)
3. Write a program to convert temperature between Celsius, Fahrenheit, and Kelvin.
(Use menu-driven program)

UNIT 2 – Control Statements & Functions


4. Write a program to generate the first N Fibonacci numbers using both loop and
recursion.
(Compare both methods)
5. Write a menu-driven program using switch-case to perform +, −, ×, ÷ operations on two
numbers.
6. Write a program to check whether a number is a palindrome or Armstrong using
functions.
7. Write a program to find factorial, combination (nCr), and permutation (nPr) using
functions.
8. Write a program using nested loops to print:
 Number triangle
 Star triangle
 Pascal's triangle
(Any one model)

UNIT 3 – Arrays, Strings & Pointers


9. Write a program to read N numbers, store them in an array, and perform:
 Sum
 Average
 Maximum
 Minimum
(Display all results)
10. Write a program to perform matrix addition, subtraction, and multiplication using 2D
arrays.
11. Write a program to sort an array using:
 Bubble Sort
 Selection Sort
12. Write a program to check whether two strings are anagrams, palindrome, or equal
using string functions.
13. Write a program to dynamically allocate memory for N students using malloc/calloc
and display details.
14. Write a program to swap two numbers using pointers and also find the larger number
using pointer arithmetic.

UNIT 4 – Structures, Unions & Enums


15. Write a program using structures to store details of N students (name, roll, marks) and
display topper.
16. Write a program using array of structures to store employee details and search for an
employee by ID.
17. Write a program using pointers to structure to read and print book details.
18. Write a program to demonstrate union behavior by storing different data types in the
same memory location.
19. Write a program to create an enum for days of the week and display the selected day
using switch-case.

UNIT 5 – File Handling & Header Files


20. Write a program to read a text file and count the number of:
 Characters
 Words
 Lines
21. Write a program to create a file and write student details, then read back and display
them.
22. Write a program to copy the contents of one file into another (like file copy command).
23. Write a program to store N numbers in a binary file and read them back using fread()
and fwrite().
24. Write a program to create a user-defined header file containing a function (square /
factorial) and use it in main file.
⭐MOST IMPORTANT (Frequently Asked in University Exams)
✔ Matrix multiplication program
✔ Fibonacci using recursion
✔ File read/write program
✔ Array of structures (student details)
✔ Sorting program (bubble or selection)
✔ Menu-driven calculator
✔ Frequency count in a text file

You might also like