Ad
Saturday, July 29, 2023
Chapter 1: Problem Solving Aspects : C Programming : FYBCS SEM 1
Q. Define Algorithm.
- An algorithm is a set of instructions to be executed to perform a specific task.
Q. Define Flowchart.
- A flowchart is a graphical representation of the algorithm. It uses standard symbols to show sequence of steps involved in completing a specific task.
Q. Differentiate between algorithm and flowchart. [5 mark]
Feature | Algorithm | Flowchart |
---|---|---|
Definition | A stepwise sequence to be followed for implementing a task. | A diagrammatic representation of the sequence to be followed. |
Time Consumption | Comparatively less time consuming. | Time-consuming task due to drawing and designing. |
Flow Representation | Cannot properly demonstrate the flow, especially for looping and branching tasks. | Shows proper flow of tasks, even for looping and branching statements. |
Representation | Presented as a set of logical steps or instructions in plain language or pseudo-code. | Displayed as a visual diagram using symbols and arrows to illustrate the sequence of steps. |
Application | Widely used in programming and problem-solving for designing computational solutions. | Applied in various fields beyond programming, such as business processes, system design, troubleshooting, and decision-making. |
-
Q. Differentiate between compiler and interpreter.
Feature | Compiler | Interpreter |
---|---|---|
Definition | Translates entire code at once | Translates and executes code line-by-line or statement-by-statement |
Execution | Creates a separate executable file | Executes code directly during interpretation process |
Process | Checks entire code for errors before execution | Reports errors as soon as they are encountered |
Speed | Faster execution as code is pre-translated | Execution might be slower due to simultaneous translation and execution |
Error Reporting | Reports errors after the entire code is checked | Reports errors immediately as they are encountered |
Examples | GCC (C/C++ compiler), Java compiler (javac) | Python interpreter, JavaScript interpreter in web browsers |
Q. What is a compiler ?
- A compiler is a type of computer program that translates the entire source code written in a high-level programming language into machine code or an intermediate code that can be executed directly by the computer's hardware.
Q. FLOWCHART SYMBOLS.
-
Name | Symbol | Use in Flowchart |
---|---|---|
Oval | ![]() |
Used for start or stop of an algorithm |
Flow Line | ![]() |
Used to denote the direction of flow |
Parallelogram | ![]() |
Used to perform input or output i.e. take input from the keyboard or give output to the monitor |
Rectangle | ![]() |
Used to indicate an operation to be performed, e.g., addition |
Diamond | ![]() |
Used to take a decision; it normally has one input and two outputs based on whether the condition checked is true or false |
----
Q. What is global variable?
- The global variables can be accessed by all the functions.
Q. What is local variable?
- The local variable are only local to the corresponding functions.
Q. What are properties of algorithm?
-
The algorithm should have following properties associated with it:
1) Finiteness: The algorithm should be finite.
2) Range of Input: The range of input for which algorithm works should be compulsorily mentioned.
3) Non-ambiguity: Each statement in algorithm must be clear and precise.
4) Speed: The algorithm should produce result at a fast speed.
5) Multiplicity: The algorithm can be represented in multiple ways i.e. (English language,flowchart,pseudo-code,etc.)
Q. What are advantages of an algorithm?
-
1) It follows a clear and specific set of instructions or steps.
2) It can be used independently without relying on a specific programming language.
3) Each step in the algorithm is logically ordered, making it easy to find and fix mistakes.
4) It divides a complex problem into smaller, manageable parts, helping the programmer to easily convert it into a real program.
Q. What are disadvantages of the algorithm?
-
1) Writing an algorithm can be time-consuming.
2) An algorithm is not an actual computer program; it's more like a plan or idea of how a program should work..
3) It's difficult to show the flow of the program, especially for branching (decision-making) and loops, in an algorithm..
Write an algorithm and draw a flowchart for ‘finding of area of traingle’
-
Q. Algorithm to Find the Area of a Triangle:
Step 1: START
Step 2: PRINT "Enter the length of the base of the triangle (b):"
Step 3: INPUT b
Step 4: PRINT "Enter the height of the triangle (h):"
Step 5: INPUT h
Step 6: area = (1/2) * b * h
Step 7: PRINT "The area of the triangle is:", area
Step 8: STOP
Q. Write an algorithm and flowchart for swap of two numbers
-
Algorithm:
Step 1: START
Step 2: PRINT "Enter the two numbers:"
Step 3: INPUT num1 & num2
Step 4: PRINT "Before swapping: num1 =", num1, "num2 =", num2
Step 5: SET temp = num1
Step 6: SET num1 = num2
Step 7: SET num2 = temp
Step 8: PRINT "After swapping: num1 =", num1, "num2 =", num2
Step 9: STOP
Q. Write algorithm and draw flowchart to find out factorial of a number.
-
Step 1: START
Step 2: PRINT "Enter a number (num):"
Step 3: INPUT num
Step 4: SET factorial = 1
Step 5: SET i = 1
Step 6: WHILE i <= num, DO Steps 7 to 9
Step 7: SET factorial = factorial * i
Step 8: SET i = i + 1
Step 9: END WHILE
Step 10: PRINT "The factorial of", num, "is:", factorial
Step 11: STOP
Q. Write an algorithm and draw a flowcahrt to find the maximum
of 3 no's.
-
Step 1: START
Step 2: PRINT "Enter the three numbers:"
Step 3: INPUT num1, num2 & num3
Step 4: IF num1 >= num2 AND num1 >= num3 THEN
Step 5: SET max = num1
Step 6: ELSE IF num2 >= num1 AND num2 >= num3 THEN
Step 7: SET max = num2
Step 8: ELSE
Step 9: SET max = num3
Step 10: END IF
Step 11: PRINT "The maximum of", num1, ",", num2, "and", num3, "is:", max
Step 12: STOP
Q. Write an algorithm and draw a flowchart for sum of digit until one digit. (w.g: 932= 9+3+2=14 1+4=5 = output)
-
Step 1: START
Step 2: PRINT "Enter a number (num):"
Step 3: INPUT num
Step 4: WHILE num >= 10, DO Steps 5 to 7
Step 5: SET sum = 0
Step 6: WHILE num > 0, DO Steps 7 and 8
Step 7: SET sum = sum + (num % 10)
Step 8: SET num = num / 10 (integer division)
Step 9: END WHILE
Step 10: SET num = sum
Step 11: END WHILE
Step 12: PRINT "The sum of digits until one digit for the given number is:", num
Step 13: STOP
About Abhishek Dhamdhere
Qna Library Is a Free Online Library of questions and answers where we want to provide all the solutions to problems that students are facing in their studies. Right now we are serving students from maharashtra state board by providing notes or exercise solutions for various academic subjects
No comments:
Post a Comment