Professional Documents
Culture Documents
Write an algorithm and flowchart to find out whether a given integer is zero, +ve or -ve
and explain it.
⇒ The algorithm to check if the given number is zero, +ve or -ve is:
Step 1. Start
Step 2. Input a number
Step 3. Compare the number with zero.
If the number is equal to zero display “The number is zero.”
If the number is less than zero display “The number is -ve.”
If the number is more than zero display “The number is +ve.”
Step 4. End
Flowchart here
2. What is a logical error ?
⇒A logic error is a mistake in a program that causes it to operate wrongly, but not to
terminate abnormally. A logic error produces unintended or undesired output.
3. Write a flowchart and program or check whether the number entered by the user is exactly
divisible by 5 or 11 .
#include<stdio.h>
int main()
{
int number;
printf(“Enter a number”);
scanf(“%d”,& number);
If (n%5==0 )
{
printf(“%d is divisible by 5”;number);
}
Elseif (n%11==0)
{
printf(“%d is divisible by 11”;number);
}
else
{
printf(“not divisible by both”);
}
return 0;
}
Flowchart here
4.Differentiate between if and switch statement.WAP to read marks off our subjects and find
total percentage and division according to given condition.
The if statement is used to select among two alternatives. It uses a boolean expression to
decide which of the alternatives should be executed.
if(condition)
{… }
else {.…..}
The switch statement is used to select among multiple alternatives. It uses an expression
to determine which alternative should be executed.
Switch(expression){
Case value1: …
Case value2: …
Default: …..
int main()
int m,c,i,d,p,t,per;
scanf("%d%d%d%d%d",&m,&c,&i,&d,&p);
t=m+c+i+d+p;
per=(t\500)*100;
printf("Distinction");
printf("First division");
printf("Second Division");
printf("Third division");
else
printf("Failed");
else
{
printf("Failed");
return 0;
Link section:The link section provides instructions to the compiler to link functions from the
system library.
Global declaration section:There are some variables that are used in more than one
function. Such variables are called global variables and are declared in the global
declaration section that is outside of all the functions. This section also declares all the
user-defined functions.
main()function section:Every C program must have one main function section. This section
contains two parts; declaration part and executable partDeclaration part : The declaration
part declares all the variables used in the executable part.Executable part : There is at least
one statement in the executable part. These two parts must appear between the opening
and closing braces. The program execution begins at the opening brace and ends at the
closing brace. The closing brace of the main function is the logical end of the program. All
statements in the declaration and executable part end with a semicolon.
Subprogram section:The subprogram section contains all the user-defined functions that
are called in the main () function. User-defined functions are generally placed immediately
after the main () function, although they may appear in any order. Note:All sections, except
the main () function section may be absent when they are not required.
STEP 1:Start
STEP 2:Initialize n
STEP 3:Input n
STEP 4:If n%5==0
If yes print divisible by 5
If no goto 5
STEP 5:If n%11==0
If yes print divisible by 11
If no print neither divisible by 5 or 11
STEP 6:End
Flowchart here
7.Draw a flowchart and an algorithm to find out whether a given number is positive, negative
or zero .
Same as no. 1
Structure is a user defined data type in C . A structure creates a data type that can be used
to group items of possibly different types of data into a single type.It is a convenient way of
grouping several pieces of related information together.
Syntax:
Struct structure_name
{
Data type varname1;
Data type varname2;
……………………………….
……………………………….
};
Array and structure both are container data type . The major difference between them is
that an array contains all the elements of the same data type with its size defined during its
declaration whereas structure contains elements of different data types and its size is
determined by the number of elements declared in a structure when it is defined.
#include<stdio.h>
Struct student
{
Char name[20];
int roll;
int percentage;
};
Void main( )
{
Struct student s[100];
int n,i;
printf(“Enter number of students”);
scanf(“%d”,&n);
printf(“Enter record of %d student”,&n);
for(i=0;i<n;i++)
{
scanf(“%s%d%d”,&s[i].name,&s[i].roll,&s[i].percentage);
}
for(i=0;i<n;i++)
{
if (s[i].percentage>=60)
{
printf(“%s\n”,s[i].name);
}
}
getch( );
}
Input:A number of quantities are provided to an algorithm initially before the algorithm
begins.These quantities are inputs which are processed by the algorithm.
Definiteness:The processing rules specified in the algorithm must be unambiguous and lead
to a specific action.
Finiteness:The total time to carry out all the steps in an algorithm must be finite.
Correctness:Correct set of output must be produced from the set of inputs.For the same
input,it must always produce the same output.
Eg;
Algorithm to find roots of quadratic equations.
STEP 1:Start
STEP 2:Input a,b,c
STEP 3:Calculate discriminant d=b^2-4*A*C
STEP 4:IF D=0 then
Print roots are equal
root1=root2=-b/2a
STEP 5:else if d>0 then
Root1=(-b+(b^2-4*A*C)^o.5)/2a
Root2=(-b-(b^2-4*A*C)^o.5)/2a
STEP 6:else print”roots are imaginary”
STEP 7:print Root1 and Root2.
STEP8:Stop
#include<stdio.h>
int main( )
{
int num;
printf(“Enter an integer”);
scanf(“%d”,&num);
if(num%2==0)
{
printf(“%d is even”,num);
}
else
{
printf(“%d is odd”,num);
}
return 0;
}
#include<stdio.h>
int main( )
{
int s=0,i;
for(i=1;i<=10;i++)
{
if(i%2!=0)
{
s=s+i;
}
}
printf(“Sum of first 10 odd numbers is %d”,s);
return 0;
}
Preprocessor directives are the lines in a C program that begins with the character #
making them different from typical source code text.They are invoked by the compiler to
process some programs before compilation...Preprocessor directive changes the text of the
source code and the result is a new source code without these directives.
Syntax
#include<stdio.h>
#define NAME”Aarav”
#define AGE 10
int main ( )
{
printf(“%s is over %d years old.”,NAME,AGE);
return 0;
}
What do you mean by programming language ? Differentiate between high level and low
level language.
A language for expressing a set of detailed instructions for a digital computer is called a
programming language.Although there are many computer languages, relatively few are widely
used.
The first high-level languages were introduced in the 1950s. Today, high-level languages are in
widespread use. These include BASIC, C, C++, COBOL, FORTRAN, Java, Pascal, Perl, PHP,
Python, Ruby, and Visual Basic.
Machine language instructions typically use some bits to represent operations, such as addition,
and some to represent operands, or perhaps the location of the next instruction. Machine
language is difficult to read and write, since it does not resemble conventional mathematical
notation or human language, and its codes vary from computer to computer.
2.Assembly Language-Assembly language is one level above machine language. It uses short
mnemonic codes for instructions and allows the programmer to introduce names for blocks of
memory that hold data. One might thus write “add pay, total” instead of “0110101100101000” for
an instruction that adds two numbers.
Assembly language is designed to be easily translated into machine language. Although blocks
of data may be referred to by name instead of by their machine addresses, assembly language
does not provide more sophisticated means of organizing complex information.
Like machine language, assembly language requires detailed knowledge of internal computer
architecture. It is useful when such details are important, as in programming a computer to
interact with input/output devices (printers, scanners, storage devices, and so forth).
Problem Analysis is the stage which begins with reviewing the program specifications indicating
what the new system should do.During this stage , the system analyst and programmer review
the specifications and possibly talk with users in order to fully understand what the software
should do .It consists of following steps :
Done
1. The Oval
An End or a Beginning
process. Remember to use the same symbol again to show that your flowchart is
complete.
2. The Rectangle
A Step in the Flowcharting Process
The rectangle is your go-to symbol once you've started flowcharting. It represents any
step in the process you’re diagramming and is the workhorse of the flowchart diagram.
Use rectangles to capture process steps like basic tasks or actions in your process.
3. The Arrow
Indicate Directional Flow
The arrow is used to guide the viewer along their flowcharting path. And while there are
many different types of arrow tips to choose from, it is recommended sticking with one
or two for your entire flowchart. This keeps your diagram looking clean, but also allows
The diamond symbolizes that a decision is required to move forward. This could be a
5.The parallelogram
Define program compilation and exclusion. Explain compilation process with suitable
block diagram.
Program compilation is the step performed on each output of the preprocessor. A code of a
program written in high level language is called source code;which is not directly
understandable by the computer.Hence, the source code should be translated into computer
The machine level code that we set after compilation is called object code.Object code is the
Execution of a program involves loading the executable object code into the computer memory
and executes the instructions.While executing the program,the program may load data from
memory or keyboard.
Explain history of c language in brief:
The C programming language came out of Bell Labs in the early 1970s. According to the Bell
Labs paper The Development of the C Language by Dennis Ritchie, “The C programming
language was devised in the early 1970s as a system implementation language for the nascent
Unix operating system. Derived from the typeless language BCPL, it evolved a type structure;
Ken Thompson, a Bell Labs employee, desired to make a programming language for the new
Unix platform. Thompson modified the BCPL system language and created B. However, not
many utilities were ever written in B due to its slow nature and inability to take advantage of
PDP-11 features in the operating system. This led to Ritchie improving on B, and thus creating
C.
The development of C was to become the basis for Unix. According to the Bell Labs paper, “By
early 1973, the essentials of modern C were complete. The language and compiler were strong
enough to permit us to rewrite the Unix kernel for the PDP-11 in C during the summer of the
year.” This now meant that C was becoming a strong language that could, and would be,
implemented across many systems. By the middle of the 1970s, the C-based Unix was used in
many projects within the Bell System as well as “a small group of research-oriented industrial,
C has changed over the years and is still a common language to use in lower level programs,
like kernels. But it is also used for many applications ranging from device drivers to other
programming languages’ compilers or interpreters. The language also made way for C++,
Objective-C, C#, and many more C-based languages that each have their own speciality.
Done
Done
Write an algorithm and flowchart to find the smallest among three numbers.
Algorithm
STEP 1:Start
If no,goto 5
If yes,print a is smallest,goto 6
If no,print c is greatest,goto 6
If no,print c is smallest,goto 6
STEP 6:end
Write an algorithm and draw a flowchart to find real roots of quadratic equation.
Done