Professional Documents
Culture Documents
ASSIGNMENT 1
4. Show results
Take input a,b
5. Stop
Sum=a+b , Sub=a-b,
mul=a*b , div=a/b,
mod=a%b
Show results
Stop
II. Calculate average of 5 numbers entered from user, display the average.
1. Start
2. Input a, b, c, d, e
START
3. Calculate average by adding all numbers and by
dividing it by 5 i.e. a + b + c + d+ e /5 and taking Its
average.
5.Stop.
Input a,b,c,d,e
average=(a+b+c+d+e
)/5
Print average
Stop
III. Print Hello 5 times.
1. Start
2. Take m =1
3. Apply the If statement given below:-int m=1;
If(m<=5)
printf(“Hello\n”);
m++;
5. Stop
IV. Perform addition on digits of a number , e.g.423=4+2+3=9 should be
returned.
1.Step
2. Take a, b, c
num%100=modulus1;
modulus1=a; num%100=modulus1
num/10; modulus1=a
num%10=modulus2; num/10
modulus2=b; num%10=modulus2
modulus2=b
num/100;
num=c;
6. Stop num=c
a+b+c
Stop
V. Reverse a program number e.g.423 should be reversed to 324.
1 . Start
Start
2. Take input a
3.
num=a%10 Input a
rev=rev*10+num
num/=10; False
a>=0 Print num=-
4. Check num>0
num
5. Go to step 3.
6. Print rev.
7. Stop.
num=a%10
rev=rev*10+num
num/=10
Print rev
Stop
VI. Check if no. is palindrome(If number and the reversed number is same)
1. Start
reverse=a%10;
reminder=reminder*10+reverse;
reverse=reminder; If a==rev
Check a>0
Go to step 3;
4. If a is equal to reverse,
print Number is palindrome
Stop
VII. Factorial of a number entered by user.
1. Start Start
2. Take input n
3. (Initialise) i=1,fact=1
Input n
4. Repeat step 4 through 6 untill i=n
5. fact=fact*i
6. i=i+1 i=1,fact=
7. Print fact 1
8. Stop
Is FALSE
i<=n?
True
I=i+1
Print fact
fact=fact*i
Stop
VIII. GCD of 2 numbers entered by user.
1. Start
4. r=a%b
Input a,b
5. While r!=0,r=n%d
6. GCD =d
7. Display GCD.
a=d,b=n
8. Stop
r=a%b
Invalid
False number
r!=0
r=n%d
d=GCD
Stop
IX. Check if a number is Prime or not.
Start
1. Start
3. Take n=2
Input p
4. Divide p by n i.e. p%n and take it r.
8. Display p is prime.
False
n= n+1
Stop
X. Check if a number entered is even or odd.
1. Start
Start
2. Take input as num
4. Stop.
num%2
=0 False Odd number
True
Even
Number
Stop
Q2. What are the characteristics of a good Algorithm along with basic definition of
Algorithm and Flowcharts.
Ans. Start/Stop
Input/Output
It is used as a connector
General Topics :
One of the overwhelming advantage of the computer lies in its very necessity.
Q2. Explain the areas where C is still used and preferred over other languages like
Java, Python, HTML, C++.
Embedded System
Open Source Software
System Programming
Controlling System
Automotive System Controllers
Network Hacking
Writing/Designing Compilers
Q3. What are the different types of computing devices which you see in day-to-day
world ?
Ans. Feature of C:
It is a robust language with rich set of built-in functions and operations that can
be used to write any complex program.
The C compiler combines the capabilities of an assembly language with
features of a high-level language.
It is mainly faster than BASIC.
Program written in C is generally fast and efficient. This is due to variety of data
type and powerful operators.
C is highly portable this means that programs once written can be run on
another machine little or no modification.
C program is basically a collection of function that are supported in C library.
We can also create our own function and add it to C library.
C language is the most widely used language in operating system and
embedded system and it has ability to extend itself.
Advantages of C language :
Disadvantages of C language :
Easier to debug
Reusable Code
Readability
Reliability
Team Programming
Manageability
The main function of the lesson is to expose the need of programming language.
When we formative language or commands that describe actions we are making a
kind of code. This is also necessary for computers, which are simply machines that
can perform a no. of different tasks.
Q7. What are high level and low level languages, advantages and disadvantages of
both languages ?
Ans. High level language provides higher level of abstraction from machine
language. They do not interact directly with the hardware. Rather, they focus more
on the complex arithmetic operations, optimal program efficiency and easiness in
coding.
High level languages are programmer friendly. They are easy to write, debug
and maintain.
It provide higher level of abstraction from machine languages.
It is machine independent language.
Easy to learn.
Less error prone, easy to find and debug errors.
Q8. Difference between compiler, interpreter, assembler and why do we need them
?
Ans. Compiler : It's a computer programs that transforms source code written in a
programming language into machine language that is the target language which
usually has a binary form known as object code.
Assembler : It is a program that takes basic computer instructions and converts then
into a pattern of bits that the computer's processor can use to perform it's basic
operations. The language used to program the assembler is called assembly
language.
Errors are displayed after entire program is checked in case of compiler. Hence
debugging is comparatively hard. In case of an interpreter, Errors are displayed for
every instruction interpreted (if any). An interpreter continues translating the
program until the first error is met, in which case it stops. Hence debugging is easy.
Q9. What are stand-alone application and web-based application, exemplify and
specify which languages are use to develop those applications ?
Ans. Stand-alone applications: Software that is not a part of some bundled software.
A program that run as a separate computer process, not an add-on of an existing
process. Standalone program, a program that does not require operating system's
services to run. A portable application, which can be run without the need for
installation procedure.
Examples: MS-Office, Picasa, WinRAR, calculator, adobe, Antivirus.
Q10. What is memory and different types (ROM, RAM, cache, secondary
storage(hard disk, u.s.b). Explain w.r.t memory cost and time to access.
Ans. Memory is a storage area in computer system. The term memory identifies
data storage that comes in the form of chips and the word storage is use for memory
that exists on tapes or disks.
Hard disk:- The hard disk or a hard drive , is a spindle of magnetic discs that
can hold several gigabytes of data. Therefore, disk space refers to how much
space is available on your hard disk for storing files.
USB:- It is a data storage device that includes flash memory with an integrated
USB interface. It is removeable and rewriteable and much smaller than a
DVD Or CD.
Q11. What is bit, byte, binary number system and decimal number system. why
computers implement binary and not any other number system like octa, hex,
decimal) ?
A byte is 8 binary digits working together to represent a number that can take a
value between 0 and 255 in the decimal system.
Decimal is a term that describes the base-10 number system, probably the most
commonly used number system. The decimal number system consists of ten
single- digit numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.
Q13. What is portability and why is code written in low level language is not
portable(high level program is) w.r.t CPU architecture. Please explain using a
sample 20 bit CPU architecture.
Ans. Portability : Portability is a characteristic attributed to a computer program if it
can be used in an operating systems other than the one in which it was created
without requiring major rework. Porting is the task of doing any work necessary to
make the computer program run in the new environment.
A low-level programming language is a programming language that
provides little or no abstraction from a computer's instruction set architecture—
commands or functions in the language map closely to processor instructions.
Generally this refers to either machine code or assembly language. The word "low"
refers to the small or nonexistent amount of abstraction between the language and
machine language; because of this, low-level languages are sometimes described
as being "close to the hardware". Programs written in low-level languages tend to be
relatively non-portable.
Low-level languages can convert to machine code without a compiler or
interpreter second-generation programming languages use a simpler processor
called an assembler— and the resulting code runs directly on the processor. A
program written in a low-level language can be made to run very quickly, with a
small memory footprint. An equivalent program in a high-level language can be less
efficient and use more memory. Low-level languages are simple, but considered
difficult to use, due to numerous technical details that the programmer must
remember. By comparison, a high-level programming language isolates execution
semantics of a computer architecture from the specification of the program, which
simplifies development.Programming exercises(in c):
1.Assign an integer value to a character variable and then display in %d
and %d format.
Output
2.Using sizeof( ) display size if all basic type of data types.
Output
Iterations:-
1.
2.
Overall(Unit 1):
1. Write a program that reads two no. from keyboard and gives addition,
subtraction, multiplication, division.
2.Program to Print Largest of Three No
3.Program for increment and decrement operators.
4.Program to convert
distance into cm, inches, m, feet entered by user in km.
5.Program for exponential series ex.
6. Write a program to implement Pascal Triangle.
7. Write a program to find sum of all integers greater than 100 & less than 200
and are divisible by 5.