Professional Documents
Culture Documents
Chapter 1
Input Unit
It is used to enter data in Computer for processing. Keyboard is the one of the most
commonly used input device. Other commonly used input devices are the mouse, scanner,
webcam, joystick.
Storage Unit(Memory)
It is used for storing the data in computer.
The various storage devices of a computer system are divided into two categories:
1. Primary Storage:
• Store current program or data
• Fast in operation
• Less storage capacity
• Costly
• Two types : RAM and ROM
• RAM – Random Access Memory. Its volatile in nature (Program gets lost when
power is turned off)
• ROM – Read Only Memory. Its non-volatile in nature. (Program stays
permanent)
2. Secondary Storage:
• Store program or data permanently
• Slow in operation
• More storage capacity
• Cheap
• Example : Hard disk, pen drive, CD, DVD
1|P a ge
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
The Control Unit (CU) and Arithmetic Logical Unit (ALU) of the computer are together
knownas the Central Processing Unit (CPU).
Output Unit:
The output unit of a computer provides the information and results of a operation to
outsideworld.
Example : Monitor, Printers ,Speakers, Projector.
Advantages:
• Easy to understand: Compared to machine language. It’s easier for people to read, write
and understand programs written in assembly language.
• Efficiency: It requires less memory and other resources as compared to high level
language.
2|P a ge
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
Disadvantages:
• Harder to learn: Different architecture have different instruction for writing assemblylanguage code.
• Time Consuming: Writing programs is time consuming process.
Interpreter Compiler
Translates program into machine Scans the entire program and then translates into
languageline by line machine language
Execution time is slower. Execution time is faster.
No intermediate object code is Generates intermediate object code which further
generated,hence are memory efficient. requires linking, hence requires more memory.
Continues translating the program until It generates the error message only after scanning
thefirst error is met, in which case it stops. the whole program.
Programming language like Python, Programming language like C, C++ use
HTML use interpreters. compilers.
II. Compiler
It is a program which translates the program written in a high level language into computer readable
machine language (binary form)
V. Assembler
Assembler in C Programming is defined as a program that converts Assembly languageinto
machine code.
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
Flowchart:
A flowchart is graphical representation of sequence of any problem to be solved by computer
programming language. Following are the flowchart symbols:
Algorithm:
Algorithm Flowchart
1 It is a finite sequence of well-defined 1 A flowchart is graphical
steps for solving a problem in systemic representation of sequence of any
manner. problem to be solved by computer
programming language.
2 It is a bit difficult to understand. 2 It is easy to understand.
3 It doesn't use any specific symbols. 3 It uses various kinds of symbols
which are interlinked with arrows.
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
1. Write flowchart or algorithm to find area of a triangle.
Solution:
Algorithm:-
Step1: Start
Step 5: Stop
Flowchart:
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
2. Sketch flowchart and write an algorithm to convert seconds into hour, minute and second.
(Hint : 3700 seconds => 1 hr , 1 minute , 40 second)
Solution:
Algorithm:
Step1: Start
m= (second%3600)/60
s= (second%3600)%60
Step 5: Stop
Flowchart:
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
3. Write an algorithm and flowchart to determine whether the given year is a leap year
or not.
Solution:
Algorithm:
Step1: Start
Step 3: if ((year%400==0) || (year%4==0 && year%100!=0) )then goto next step otherwise goto
step 6.
Step 5: stop
Step 7: stop
Flowchart:
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
4. Write an algorithm for finding odd and even number from given two numbers.
Solution:
Algorithm:
Step1: Start
Step 9: Stop
Flowchart:-
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
5. Write an algorithm for finding largest Number out of three given Numbers. Draw the Flowchart
for finding largest Number out of three given Numbers.
Solution:
Algorithm:
Step-1: Input a, b, c
Step-2: if a > b then goto next step otherwise goto step 8
Step-3: if a > c then goto next step otherwise goto step 6
Step-4: print, “Max num is”, a
Step-5: stop
Step-6: print, “Max num is”, c
Step-7: stop
Step-8: if b > c then goto next step otherwise goto step 11
Step-9: print, “Max num is”, b
Step-10: stop
Step-11: print, “Max num is”, c
Step-12: stop
Flowchart:
Start
Input a, b, c
False True
Is (a>b)
True
Is (a>c) ?
Is (b>c)
False True False
Print ,”Max
Print ,”Max Print ,”Max num is”, a
Print ,”Max
num is”, b num is”, c
num is”, c
Stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
6. Write an algorithm and draw the flowchart to find root of equation: ax2 + bx + c.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read a,b,c
Step 3: d = b * b – 4 * a * c
Step 4: if d >= 0 then goto next step otherwise goto step 9
Step 5: x1 = ( - b + √d ) / 2 * a
Step 6: x2 = ( - b - √d ) / 2 * a
Step 7: print, x1, x2
Step 8: stop
Step 9: print, “Negative Roots possible.”
Step 10: stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
7. Write an algorithm and draw the flowchart to find factorial of given number.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read num
Step 3: count=1, fact=1
Step 4: Repeat steps from 4 to step 6 until count<= num
Step 5: fact = fact * count
Step 6: count = count + 1
Step 7: print, “Ans =”, fact
Step 8: stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
8. Write an algorithm and draw the flowchart to find sum of first N element.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read num
Step 3: count=1, sum=0
Step 4: Repeat steps from 4 to step 6 until count<= num
Step 5: sum = sum + count
Step 6: count = count + 1
Step 7: print, “Ans =”, sum
Step 8: stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
9. Write an algorithm and draw the flowchart to find sum of 10 elements read from the user.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: count = 1, sum = 0
Step 3: Repeat steps from 3 to step 6 until count<= 10
Step 4: Read num
Step 5: sum = sum + num
Step 6: count = count + 1
Step 7: print, “Ans =”, sum
Step 8: stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
10. Write an algorithm and draw the flowchart to add first N odd numbers.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read n
Step 3: sum = 0, i = 1
Step 4: Repeat steps from 4 to step 6 until i <= 2*n
Step 5: sum = sum + i
Step 6: i = i + 2
Step 7: print, “Ans =”, sum
Step 8: stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
11. Write an algorithm and draw the flowchart to accept N numbers & count how many of them
where odd and also compute sum of all these odd numbers.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read N
Step 3: count = 1, sum = 0, odd = 0
Step 4: Repeat steps from 4 to step 9 until count<= N
Step 5: Read num
Step 6: if num % 2 = 1 then goto next step otherwise goto step 9
Step 7: odd = odd + 1
Step 8: sum = sum + num
Step 9: count = count + 1
Step 10: print, “Odd Count =”, odd, “Sum=”, sum
Step 11: Stop.
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
12. Write an algorithm and draw the flowchart to print sum of numbers between 1 to 100 which
are divisible by 3 and 5.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: count = 1, sum = 0
Step 3: Repeat steps from 3 to step 6 until count<= 100
Step 4: if count % 3 = 0 && count % 5 = 0 then goto next step otherwise goto step 6
Step 5: sum = sum + count
Step 6: count = count + 1
Step 7: print, “Ans =”, sum
Step 8: stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
13. Write an algorithm and draw the flowchart to solve following series 1! + 2! + 3! + …..+ n!
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read N
Step 3: count = 1, sum = 0, fact = 1
Step 4: Repeat steps from 4 to step 7 until count<= N
Step 5: fact = fact * count
Step 6: sum = sum + fact
Step 7: count = count + 1
Step 8: print, “Ans =”, sum
Step 9: stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
14. Write an algorithm and draw the flowchart to print first N Fibonacci numbers.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read N
Step 3: a = 0, b = 1
Step 4: if N < 0 then goto next step otherwise goto step 7
Step 5: print, “Invalid Number.”
Step 6: Stop
Step 7: print, b
Step 8: count = 2
Step 9: Repeat steps 9 to steps 14 until count < = N
Step 10: c = a + b
Step 11: print, c
Step 12: a = b
Step 13: b = c
Step 14: count = count + 1
Step 15: stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
15. Write an algorithm and draw the flowchart to print reverse a given number.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read num
Step 3: sum = 0
Step 4: Repeat step 4 to steps 7 until num > 0
Step 5: r = num % 10
Step 6: sum = sum * 10 + r
Step 7: num = num / 10
Step 8: print, “Ans =”, sum
Step 9: Stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
16. Write an algorithm and draw the flowchart to print sum of individual digits of a given number.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read num
Step 3: sum = 0
Step 4: Repeat step 4 to steps 7 until num > 0
Step 5: r = num % 10
Step 6: sum = sum + r
Step 7: num = num / 10
Step 8: print, “Ans =”, sum
Step 9: Stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
17. Write an algorithm and draw the flowchart to check whether given number is Palindrome or
not.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read num
Step 3: temp = num, sum = 0
Step 4: Repeat step 4 to steps 7 until num > 0
Step 5: r = num % 10
Step 6: sum = sum*10 + r
Step 7: num = num / 10
Step 8: if sum = temp then goto next step otherwise goto step 11
Step 9: print, “Palindrome Number.”
Step 10: Stop
Step 11: print, “Not a Palindrome Number.”
Step 12: Stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
18. Write an algorithm and draw the flowchart to check whether given number is Armstrong
number or not.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read num
Step 3: temp = num, sum = 0
Step 4: Repeat step 4 to steps 7 until num > 0
Step 5: r = num % 10
Step 6: sum = sum + r*r*r
Step 7: num = num / 10
Step 8: if sum = temp then goto next step otherwise goto step 11
Step 9: print, “Armstrong Number.”
Step 10: Stop
Step 11: print, “Not an Armstrong Number.”
Step12:Stop
L. J. Institute of Engineering and Technology
Programming with JAVA Notes
19. Write an algorithm and draw the flowchart to check whether given number is Prime number
or not.
Solution:
Flowchart:
Algorithm:
Step 1: Start
Step 2: Read num
Step 3: count = 2
Step 4: Repeat steps from 4 to steps 8 until count < num
Step 5: if num % count = 0 then goto next step otherwise goto step 8
Step 6: print, “Not a Prime Number.”
Step 7: Stop.
Step 8: count = count + 1
Step 9: print, “Prime Number.”
Step 10: Stop
*********************************************************************************