0% found this document useful (0 votes)
3 views

C Programming Solution

Uploaded by

Nitesh Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

C Programming Solution

Uploaded by

Nitesh Yadav
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Group A: Very Short Questions [4×2=8]

1. Define Assembler, Compiler and Interpreter.


o Assembler: An assembler is a program that converts assembly language into machine
code. Assembly language is low-level and closely related to machine code, so the
assembler's job is to convert it into a format the computer's CPU can execute.
Example: Converting MOV AX, BX (assembly instruction) to binary code.
o Compiler: A compiler translates the entire source code written in a high-level
programming language (like C or Java) into machine code before execution. It performs
tasks like syntax analysis, optimization, and code generation. The output is an executable
file.
Example: Compiling a C program to produce an .exe file.
o Interpreter: An interpreter executes the code line-by-line instead of compiling it into an
executable file. It checks for errors in each line and stops if an error is found.
Example: Python and JavaScript interpreters.

2. Write an algorithm and draw the flowchart to find the simple interest.
Algorithm:

Step 1: Start

Step 2: Input the values of principal (P), rate of interest (R), and time (N).

Step 3: Calculate the simple interest using the formula: I = (P × R × T) / 100.

Step 4: Display the calculated value of simple interest.

Step 5: End
Flowchart:
3. What are algorithms and flowchart?
o Algorithm: An algorithm is a step-by-step procedure to solve a problem or perform a
computation. It is written in plain language or pseudocode and provides a clear set of
instructions for solving a specific task.
o Flowchart: A flowchart is a graphical representation of an algorithm. It uses standard
symbols like rectangles (process), diamonds (decisions), and ovals (start/end) to illustrate
steps.

4. Define Loops. What are the different types of loops in C?


o Loops: A loop is a control structure that allows repeated execution of a block of code
based on a condition. It minimizes redundant code by automating repetitive tasks.
▪ Types of loops are presented below: -
a) for loop
b) while loop
c) do-while loop

Group B: Short Questions [5×4=20]


5. Write a program to check whether the given number is odd or even.
6. What are the steps involved in problem solving using computer?
Problem Definition: Understand the problem requirements, inputs, and expected outputs.
Analysis: Break the problem into smaller, manageable parts and decide the approach.
Algorithm Design: Develop step-by-step instructions to solve the problem.
Coding: Translate the algorithm into a programming language.
Testing and Debugging: Check for errors and ensure the program runs as expected.
Documentation: Prepare detailed documentation for future reference and maintenance.
7. Differentiate between while loop and do-while loop with examples.
Differentiate between while loop and do-while loop are presented below in the given table.

While Loop Do-While Loops


1. Condition bottom is at the bottom.
1. Condition is at top.
2. Brackets are compulsory even if there is
2. No necessity of bracket if there is no
a single statement.
single statement in body
3. The semicolon is compulsory at the end
3. There is no semicolon at the end of
do-while
while.
4. Computer executes the body at least
4. A computer executes the body if and
once even if the condition is false.
only if the condition is true.
5. This should be used when the process is
5. This should be used when condition is
important.
more important.
6. Syntax: do {statements}
6. Syntax: while(condition) {statements}
while(condition);
8. Write a program to find the largest number from the array.

9. Differentiate between structure and union with example.


Structure Union
1. The keyword ‘struct’ is used to declare 1. The keyword ‘union’ is used to declare
a structure. a union.
2. Structure is a user define datatype. 2. Union is also user defined datatype.
3. Individual member can be accessed at a 3. Only one member can be accessed at a
time. time.
4. Structure elements don’t share their 4. Largest elements memory is shared by
memory. other elements of union.
5. All the members in a structure are active 5. Only one data member is active at a
at the same time. time.
6. Memory is allocated for each member. 6. Memory is allocated for largest member.
10. Write a program to create a structure named player with data members:
name, run scored, and country. Take input for 100 players and display the
records.
11. Discuss any two string handling functions with their syntax and write a
program to reverse a number please solve the question with more lines and
in detailed.
o String Handling Functions: -
a) strlen: Finds the length of a string.
Syntax: int length = strlen(string);
b) strcopy: Copies one string to another
Syntax: strcopy(destination, source);
o Program to Reverse a Number:

!!! COMPLETE !!!

You might also like