NAME :SAMIRAN DALAPATI; UID :TNU2024053100074; SUB:PROGRAMMING FOR
PROBLEM SOLVING
1. What is Data?
Data refers to raw, unorganized facts and figures that lack context or meaning. For example,
numbers, characters, or images that are not yet processed.
Example: Names of students, test scores, dates, "12345", "Blue", or "98.6°F".
2. What’s the difference between Data and Information?
Data: Raw facts or unprocessed content. Example: "100, 200, 300."
Information: Processed data that has meaning. Example: "Temperatures recorded over three
days: 100°C, 200°C, 300°C."
3. What do mean by Data Types?
Data types define the kind of data a variable can hold. Common data types include:
Integer: Whole numbers (e.g., 10, -5){1 byte}
Float: Real numbers with decimal points (e.g., 3.14, -2.5){4 byte}
Character: Single characters (e.g., 'a', 'Z'){1 bytes}
String: Sequences of characters (e.g., "Hello, world!"){8 bytes}
Boolean: True or false values(0 ,1){1 byte}
Double: large or heavy numbers(12345){8 bytes}
Long double: more than double data (1234556789){16 bytes}
4. What is an algorithm?
An algorithm is a step-by-step procedure for solving a problem or performing a task.
Example: Algorithm to add two numbers:
Step 1:Start.
Step 2:Input two numbers: a and b.
Step 3:Calculate sum = a + b.
Step 4:Print sum.
Step 5:Stop.
5. What is Flowchart?
A flowchart is a graphical representation of an algorithm or process, using symbols to represent
actions, decisions, and workflows.
6. What are different symbols used in Flowchart?
Common flowchart symbols include:
Oval: Start/End
Rectangle: Process
Diamond: Decision
Parallelogram: Input/Output
Arrow: Flow direction
7. What is Pseudo-code?
Pseudo-code is a way to describe an algorithm in plain language and logical steps, without
using specific syntax.
Example:
Start
Input a, b
Sum = a + b
Print Sum
End
8. What is Expression?
An expression is a combination of values, variables, and operators that produce a result.
Example:
3 + 5, x * y, or a > b.
9. Define Statement
A statement is a single line of code that performs an action.
Example: print("Hello, World!")
[Link] Program
A program is a set of instructions written in a programming language to perform a specific task.
[Link] is loop?
A loop repeats a block of code as long as a condition is true.
Types:
for loop
while loop
do-while loop
[Link] the syntax of for loop?
Syntax of for loop:
for (initialization; condition; increment/decrement) {
// code to be repeated
}
[Link] function?
A function is a block of code that performs a specific task. It can take input parameters,
process them, and return a value. Functions help in modularizing code and making it reusable.
[Link] is Nested loop?
A nested loop is a loop within another loop. It's used to create complex patterns or iterate over
multiple dimensions of data.
[Link] is Modular Programming?
Dividing a program into smaller, reusable modules or functions.
Example: A billing system with separate modules for inventory, sales, and taxes.
[Link] is goto statement?
Dividing a program into smaller, reusable modules or functions.
Example: A billing system with separate modules for inventory, sales, and taxes.
[Link] the syntax of for loop?
Syntax of for loop:
for (initialization; condition; increment/decrement) {
// code to be repeated
}
[Link] is conditional statement?
Conditional statements execute code based on conditions.
Example:
int age;
printf("Enter your age: ");
scanf("%d", &age);
if (age >= 18) {
printf("You are an adult.\n");
}
else { printf("You are a minor.\n");
}
[Link] of Loops?
There are three types of loop :
for loop: Iterates over a sequence.
while loop: Repeats while a condition is true.
do-while loop: Executes at least once before checking the condition.
[Link] is iteration?
Iteration is the repetition of a code block within a loop.
[Link] is the full form of IDE?
Full form of IDE is Integrated Development Environment.
[Link] is Variable?
A variable is a named memory location used to store data.
Example: x = 5
[Link] input/output units?
Input Unit: Accepts data from the user (e.g., keyboard, mouse).
Output Unit: Displays results (e.g., monitor, printer).
[Link] is Control Structures?
Control structures dictate the flow of execution:
Sequential: Code executes line by line.
Selection: Makes decisions (if-else).
Iteration: Repeats code (loops).
[Link] syntax of else..if?
Syntax of if-else :
if (condition1) {
// Code to execute if condition1 is true
} else if (condition2) {
// Code to execute if condition2 is true
} else {
// Code to execute if none of the conditions above are true
}
[Link] is parameter of function?
Parameters are inputs to functions.
[Link] the syntax of function?
Syntax of function:
returnType functionName(parameters) {
// Code
return value;
}
[Link] is return value?
The output value a function sends back to the caller.
[Link] is break statement?
A statement that exits a loop prematurely.
[Link] is OOP?
Object-Oriented Programming, a paradigm based on objects and classes.
[Link] is Object?
An instance of a class with attributes and behaviors.
[Link] is Class?
A blueprint for creating objects.
[Link] is Attribute?
A property of an object, such as its data.
[Link] is Array?
A collection of elements stored in contiguous memory locations.
[Link] of Array?
Syntax of array:
dataType arrayName[size];
[Link] is Structure?
A user-defined data type that groups related variables.
[Link] is pointer?
A variable that stores the memory address of another variable.
[Link] the Flowchart for Nested if- else loop and explain.
Explanation:
1. Start: The flowchart begins with a start symbol.
2. Condition 1: The first condition is checked.
If Yes: The flowchart proceeds to the next condition.
If No: The flowchart jumps to Condition 3.
3. Condition 2: The second condition is checked (nested within the first).
If Yes: Action 1 is performed.
If No: Action 2 is performed.
4. Condition 3: This condition is checked if the first condition was false.
If Yes: Action 3 is performed.
If No: Action 4 is performed.
5. End: The flowchart ends.
[Link] are the different components of function in programming? Explain.
There are four type of components of function:
● Function Name
● Parameters
● Body
● Return Value
[Link] is Precedence and Associativity?
● Precedence: Precedence determines the order of operator evaluation.
● Associativity:Associativity determines the direction of evaluation.
[Link] is BODMAS rule?
A mathematical rule defining the order of operations: Brackets, Orders, Division/Multiplication,
Addition/Subtraction.
[Link] Break statement in programming concepts?with example.
Example of break statement:
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
if (i == 5) {
break; // Exit the loop when i reaches 5
}
printf("%d ", i);
}
return 0;
}
Use code with caution.
Output:
1234
In this example:
The for loop is designed to iterate from 1 to 10.
Inside the loop, an if condition checks if i is equal to 5.
If the condition is true, the break statement is executed, causing the loop to terminate
immediately.
The loop continues to print numbers until the break statement is encountered.
Example: Breaking out of a while loop
[Link] is Parameter passing into function? Example
This refers to how arguments are passed to a function when it is called. For example:
void add(int a, int b) {
printf("%d", a + b);
}
[Link] is call by value? Example
This refers to how arguments are passed to a function when it is called. For example:
void add(int a, int b) {
printf("%d", a + b);
}
[Link] is call by reference? Example
In call by reference, a reference (address) to the actual parameter is passed, allowing
modifications to affect the original variable.
Example:-
void func(int *x) {
*x = *x + 10;
}
[Link] is the difference between 1D and 2D arrays? Example
1D Arrays( Linear array)
● Single dimension: A 1D array represents a linear sequence of elements, each identified
by a single index.
● Access: Elements are accessed using a single index, like array[index].
Example:
int numbers[5] = {10, 20, 30, 40, 50};
2D Arrays (Array with rows and columns)
● Multiple dimensions: A 2D array represents a matrix or table of elements, organized into
rows and columns.
● Access: Elements are accessed using two indices, like array[row][column].
Example:
int matrix[3][3] = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
[Link] Pointer with programming example?
Pointer with Programming Example:
int var = 20;
int *ptr = &var;
printf("%d", *ptr);
[Link] are the differences between Array and Structure? Example
Array
● Homogeneous data: All elements must be of the same data type.
●
● Fixed size: The size must be declared at compile time.
● Access: Elements are accessed using an index.
●
● Memory allocation: Contiguous memory allocation.
●
Example:
int numbers[5] = {10, 20, 30, 40, 50};
Structure
● Heterogeneous data: Can contain elements of different data types.
●
● User-defined data type: Defined using the struct keyword.
● Access: Elements are accessed using the dot operator (.).
● Memory allocation: Not necessarily contiguous memory allocation.
●
Example:
struct Student {
int roll_no;
char name[20];
float marks;
};
struct Student student1 = {101, "Alice", 95.5};
[Link] Array indexing with example?
Array indexing is a mechanism used to access individual elements within an array. In C, arrays
are zero-indexed, meaning the first element is at index 0, the second at index 1, and so on.
Syntax:
array_name[index]
● arrayname: The name of the array.
● index: The position of the element you want to access, starting from 0.
Example:
#include <stdio.h>
int main() {
int numbers[5] = {10, 20, 30, 40, 50};
printf("First element: %d\n", numbers[0]);
printf("Last element: %d\n", numbers[4]);
return 0;
}
Output:
First element:10
Last element:50
[Link] the Expression: X= ((A + B - ((C * D) /E))) - F % D) , if A = 2, B=1, C=4,
D=1, E=2, F=4.
[Link] the Algorithm, Flowchart, Pseudocode and C Program to accept
two numbers
from users, compute summation and print the Result.
Algorithm:
Step 1:Start.
Step 2:Accept two numbers, num1 and num2.
Step 3:Compute sum = num1 + num2.
Step 4:Display the result.
Step 5:Stop.
Flowchart:
Pseudocode:
BEGIN
PRINT "Enter the first number:"
INPUT num1
PRINT "Enter the second number:"
INPUT num2
sum ← num1 + num2
PRINT "The sum is:", sum
END
Program:
#include <stdio.h>
int main() {
int num1, num2, sum;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
sum = num1 + num2;
printf("The sum is: %d\n", sum);
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program to enter a number from a
user and check the no. is greater than 10 or not.
Algorithm:
Step 1:Start.
Step 2:Accept a number num.
Step3:If num > 10, display "The number is greater than 10."
Step4:Else, display "The number is not greater than 10."
Step5:Stop.
Flowchart:
Pseudocode:
BEGIN
PRINT "Enter a number:"
INPUT num
IF num > 10 THEN
PRINT "The number is greater than 10."
ELSE
PRINT "The number is not greater than 10."
ENDIF
END
Program:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num > 10) {
printf("The number is greater than 10.\n");
} else {
printf("The number is not greater than 10.\n");
}
return 0;
}
[Link] day, the courier service delivers some letters. The number of letters is different
each day. Regardless of the number of letters delivered by the courier service, they are
paid a carrying charge of $5.
Algorithm:
Step 1:Start.
Step 2:Accept the number of letters delivered (`num_letters`).
Step 3:Assign a carrying charge of $5.
Step 4:Display the carrying charge.
Step 5:Stop.
Flowchart:
Pseudocode:
BEGIN
PRINT "Enter the number of letters delivered:"
INPUT num letters
Carrying charge = 5
PRINT "Carrying charge is: $", carrying_charge
END
Program:
#include <stdio.h>
int main() {
int num_letters;
printf("Enter the number of letters delivered: ");
scanf("%d", &num_letters);
printf("Carrying charge is: $5\n");
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program to accept item name,
price, and quantity. You need to calculate value as the product of price and quantity,
and display the calculated value and the item name using variables.
Algorithm:
Step 1: Start.
Step 2: Accept the item name, price, and quantity.
Step 3: Compute `total_value = price * quantity`.
Step 4:Display the item name and total value.
Step 5:Stop.
Flowchart:
Pseudocode:
BEGIN
PRINT "Enter the item name:"
INPUT item_name
PRINT "Enter the price of the item:"
INPUT price
PRINT "Enter the quantity of the item:"
INPUT quantity
total_value = price * quantity
PRINT "Item:", item_name
PRINT "Total value is: $", total_value
END
Program:
#include <stdio.h>
int main() {
char item_name[50];
float price, total_value;
int quantity;
printf("Enter the item name: ");
scanf("%s", item_name);
printf("Enter the price of the item: ");
scanf("%f", &price);
printf("Enter the quantity of the item: ");
scanf("%d", &quantity);
total_value = price * quantity;
printf("Item: %s\n", item_name);
printf("Total value is: $%.2f\n", total_value);
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program to Accept two numbers
and print the larger of the two numbers.
Algorithm:
Step 1: Start.
Step 2: Accept two numbers, `num1` and `num2`.
Step3: Compare `num1` and `num2`:
- If `num1 > num2`, display `num1`.
Step 4: Else, display `num2`.
Step5: Stop.
Flowchart:
Pseudocode:
BEGIN
PRINT "Enter the first number:"
INPUT num1
PRINT "Enter the second number:"
INPUT num2
IF num1 > num2 THEN
PRINT "The larger number is:", num1
ELSE
PRINT "The larger number is:", num2
ENDIF
END
Program:
#include <stdio.h>
int main() {
int num1, num2;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
if (num1 > num2) {
printf("The larger number is: %d\n", num1);
} else {
printf("The larger number is: %d\n", num2);
}
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program to Print the value of nX
only if the value of nX is greater than 10 and nX is an even number.
Algorithm:
Step 1:Start.
Step 2:Accept a number `nX`.
Step 3:Check if `nX > 10` and `nX % 2 == 0`:
Step 4: If true, display the value of `nX`.
Step 5: Otherwise, display "Condition not met."
Step 6:Stop.
Flowchart:
Pseudocode:
BEGIN
PRINT "Enter the value of nX:"
INPUT nX
IF nX > 10 AND nX % 2 == 0 THEN
PRINT "The value of nX is:", nX
ELSE
PRINT "Condition not met."
ENDIF
END
Program:
#include <stdio.h>
int main() {
int nX;
printf("Enter the value of nX: ");
scanf("%d", &nX);
if (nX > 10 && nX % 2 == 0) {
printf("The value of nX is: %d\n", nX);
} else {
printf("Condition not met.\n");
}
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program to decide about the
discount percentage on a TV, the sales person needs to check the type of TV. If the TV
is Black and White [B], the discount will be 5 percent of the selling price. If the type
of TV is coloured [C], then he has to verify the size of TV screen. For 14 inches screen,
discount is 8 percent of the selling price and for 21 inches screen, the discount is 10
percent of the selling price. Write a pseudocode to show the discount percentage.
Algorithm:
Step 1:Start.
Step 2: Accept the type of TV (`type`) and selling price (`price`).
Step 3:If `type` is "B" (Black and White), discount = 5% of `price`.
Step 4:If `type` is "C" (Color TV), check the screen size:
Step 5: For 14-inch screens, discount = 8% of `price`.
Step 6: For 21-inch screens, discount = 10% of `price`.
Step 7:Compute the final discount and display it.
Step 8:Stop.
Flowchart:
Pseudocode:
BEGIN
PRINT "Enter the type of TV (B for Black and White, C for Color):"
INPUT type
PRINT "Enter the selling price of the TV:"
INPUT price
IF type == "B" THEN
discount = 0.05 * price
ELSE IF type == "C" THEN
PRINT "Enter the screen size (14 or 21):"
INPUT size
IF size == 14 THEN
discount = 0.08 * price
ELSE IF size == 21 THEN
discount = 0.10 * price
ENDIF
ENDIF
PRINT "The discount amount is: $", discount
END
Program:
#include <stdio.h>
int main() {
char type;
float price, discount = 0.0;
int size;
printf("Enter the type of TV (B for Black and White, C for Color): ");
scanf(" %c", &type);
printf("Enter the selling price of the TV: ");
scanf("%f", &price);
if (type == 'B' || type == 'b') {
discount = 0.05 * price;
} else if (type == 'C' || type == 'c') {
printf("Enter the screen size (14 or 21): ");
scanf("%d", &size);
if (size == 14) {
discount = 0.08 * price;
} else if (size == 21) {
discount = 0.10 * price;
}
}
printf("The discount amount is: $%.2f\n", discount);
return 0;
}
[Link] is writing the algorithm for automated telephone call transfer to various
departments of the company such as Marketing, Finance, Customer Care, Human
Resource (HR), and Information.
Write the Algorithm, Flowchart, Pseudocode and C Program
Algorithm:
Step 1:Start.
Step 2:Accept the department selection input (`choice`).
Step 3: If 1, transfer the call to Marketing.
Step 4: If 2, transfer the call to Finance.
Step 5: If 3, transfer the call to Customer Care.
Step 6:If 4, transfer the call to Human Resource.
Step7:If 5, transfer the call to Information.
Step 9: Otherwise, display "Invalid choice."
Step 10:Stop.
Flowchart:
Pseudocode:
BEGIN
PRINT "Select a department:"
PRINT "1. Marketing"
PRINT "2. Finance"
PRINT "3. Customer Care"
PRINT "4. Human Resource"
PRINT "5. Information"
INPUT choice
IF choice == 1 THEN
PRINT "Call transferred to Marketing."
ELSE IF choice == 2 THEN
PRINT "Call transferred to Finance."
ELSE IF choice == 3 THEN
PRINT "Call transferred to Customer Care."
ELSE IF choice == 4 THEN
PRINT "Call transferred to Human Resource."
ELSE IF choice == 5 THEN
PRINT "Call transferred to Information."
ELSE
PRINT "Invalid choice."
ENDIF
END
Program:
#include <stdio.h>
int main() {
int choice;
printf("Select a department:\n");
printf("1. Marketing\n");
printf("2. Finance\n");
printf("3. Customer Care\n");
printf("4. Human Resource\n");
printf("5. Information\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Call transferred to Marketing.\n");
break;
case 2:
printf("Call transferred to Finance.\n");
break;
case 3:
printf("Call transferred to Customer Care.\n");
break;
case 4:
printf("Call transferred to Human Resource.\n");
break;
case 5:
printf("Call transferred to Information.\n");
break;
default:
printf("Invalid choice.\n");
}
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program where interest is
calculated and displayed for the given balance and rate.
Algorithm:
Step 1:Start.
Step 2:Accept the balance (`balance`) and interest rate (`rate`).
Step 3:Compute `interest = balance * (rate / 100)`.
Step 4:Display the interest.
Step 5:Stop.
Pseudocode:
BEGIN
PRINT "Enter the balance:"
INPUT balance
PRINT "Enter the interest rate (percentage):"
INPUT rate
interest = balance * (rate / 100)
PRINT "The interest is:", interest
END
Flowchart:
Program:
#include <stdio.h>
int main() {
float balance, rate, interest;
printf("Enter the balance: ");
scanf("%f", &balance);
printf("Enter the interest rate (percentage): ");
scanf("%f", &rate);
interest = balance * (rate / 100);
printf("The interest is: $%.2f\n", interest);
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program where a number is
incremented by 1.
Algorithm:
Step 1: Start.
Step 2: Accept a number (`num`).
Step 3: Compute `num = num + 1`.
Step 4: Display the incremented number.
Step 5: Stop.
Pseudocode:
BEGIN
PRINT "Enter a number:"
INPUT num
num = num + 1
PRINT "The incremented number is:", num
END
Flowchart:
Program:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
num = num + 1;
printf("The incremented number is: %d\n", num);
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program to calculate the sum of 10
numbers entered by the user.
Algorithm:
Step 1: Start.
Step 2: Initialize `sum = 0`.
Step 3: Repeat for 10 iterations:
- Accept a number (`num`).
Step 4: Add `num` to `sum`.
Step 5: Display the sum.
Step 6: Stop.
Pseudocode:
BEGIN
sum = 0
FOR i = 1 TO 10 DO
PRINT "Enter number", i, ":"
INPUT num
sum = sum + num
ENDFOR
PRINT "The sum of the 10 numbers is:", sum
END
Flowchart:
Program:
#include <stdio.h>
int main() {
int i, num, sum = 0;
for (i = 1; i <= 10; i++) {
printf("Enter number %d: ", i);
scanf("%d", &num);
sum += num;
}
printf("The sum of the 10 numbers is: %d\n", sum);
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program to calculate average
marks of 10 students
Algorithm:
Step 1: Start.
Step2: Initialize `sum = 0`.
Step 3: Repeat for 10 iterations:
- Accept marks for each student (`marks`).
Step 4: Add `marks` to `sum`.
Step 5: Compute `average = sum / 10`.
Step 6: Display the average.
Step 7: Stop.
Pseudocode
BEGIN
sum = 0
FOR i = 1 TO 10 DO
PRINT "Enter marks for student", i, ":"
INPUT marks
sum =sum + marks
ENDFOR
average = sum / 10
PRINT "The average marks are:", average
END
Flowchart:
Program:
#include <stdio.h>
int main() {
int i, marks;
float sum = 0, average;
for (i = 1; i <= 10; i++) {
printf("Enter marks for student %d: ", i);
scanf("%d", &marks);
sum += marks;
}
average = sum / 10;
printf("The average marks are: %.2f\n", average);
return 0;
}
[Link] total expenditure on salaries for the month needs to be calculated. As per
company
policy an employee receives a minimum of $500. Depict the logic for automating the
task by using Algorithm, Flowchart, Pseudocode and C Program.
Algorithm:
Step1: Start.
Step 2: Accept the number of employees (`num_employees`).
Step 3: Initialize `total_salary = 0`.
Step 4: Repeat for `num_employees` iterations:
- Accept salary for each employee (`salary`).
Step 5: If `salary < 500`, set `salary = 500`.
Step 6: Add `salary` to `total_salary`.
Step 7: Display the total salary.
Step 8: Stop.
Pseudocode:
BEGIN
PRINT "Enter the number of employees:"
INPUT num_employees
total_salary ← 0
FOR i = 1 TO num_employees DO
PRINT "Enter salary for employee", i, ":"
INPUT salary
IF salary < 500 THEN
salary = 500
ENDIF
total_salary = total_salary + salary
ENDFOR
PRINT "The total expenditure on salaries is:", total_salary
END
Program:
#include <stdio.h>
int main() {
int i, num_employees, salary, total_salary = 0;
printf("Enter the number of employees: ");
scanf("%d", &num_employees);
for (i = 1; i <= num_employees; i++) {
printf("Enter salary for employee %d: ", i);
scanf("%d", &salary);
if (salary < 500) {
salary = 500;
}
total_salary += salary;
}
printf("The total expenditure on salaries is: $%d\n", total_salary);
return 0;
}
[Link] the Algorithm, Flowchart, Pseudocode and C Program to display all the even
numbers upto 100
Algorithm:
Step1:Start.
Step 2:Initialize `num = 2`.
Step 3: Repeat while `num <= 100`:
Step 4: Display `num`.
Step 5:Increment `num` by 2.
.Step 6:Stop.
Pseudocode:
BEGIN
num = 2
WHILE num <= 100 DO
PRINT num
num =num + 2
ENDWHILE
END
Program:
#include <stdio.h>
int main() {
int num;
for (num = 2; num <= 100; num += 2) {
printf("%d\n", num);
}
return 0;
}