Flowchart and Algorithm
Flowchart and Algorithm
READ
m1,m2,m3,m4,m5,sum,per
Sum =m1+m2+m3+m4+m5
Per=sum/5
stop
Q2:WRITE A PROGRAM THAT CALCULATES SIMPLE
INTEREST AND COMPOUND INTEREST GIVEN THAT
THE PRINCIPAL AMOUNT ,RATE OF INTEREST AND
TIME ARE ENTERED THROUGH KEYBOARD.
ALGORITHM:
Step 1: Start
Step 2: Read p,r,t,n,si,ci.
Step 3: Si=(p*r*t)/100.
Step 4: Ci=p*pow((1=r/n),n*t)-p.
Step 5: Print si and ci.
Step 6: Stop
FLOWCHART:
start
READ
p,r,t,n,si,ci
Si=(p*r*t)/100
Ci=p*pow((1=r/n),n*t)-p
Print si and ci
stop
Q3:WRITE A PROGRAM TO CALCULATE AREA AND
CIRCUMFERENCE OF A CIRCLE.
ALGORITHM
Step 1: Start
Step 2: Read r,area,circum
Step 3: Area=3.14*r*r
Step 4: Circum=2*3.14*r
Step 5: Print area and circum
Step 6: Stop
FLOWCHART
start
Read r,area,circum
Area=3.14*r*r
Circum=2*3.14*r
stop
Q4:WRITE A PROGRAM THAT ACCEPTS TEMPERATURE
IN CENTIGRADE AND CONVERT INTO FAHRENHEIT.
ALGORITHM
Step 1: Start
Step 2: Read c,f
Step 3: f=(9*c)/5+32
Step 4: Print f
Step 5: Stop
FLOWCHART
start
Read c,f
f=(9*c)/5+32
Print f
stop
Q5: a: WRITE A PROGRAM THAT SWAPS VALUES OF
TWO VARIABLES USING A THIRD VARIABLE.
ALGORITHM
Step 1: Start
Step 2: Read a,b,c
Step 3: Print value of a and b before swapping
Step 4: c=a;
a=b;
b=a;
Step 5: print value of a and b after swapping
Step 6: stop
FLOWCHART
Start
Read a,b,c
Print value of a
and b before swapping
c=a
a=b
b=c
stop
Q5:b: WRITE A PROGRAM THAT SWAPS VALUES OF
TWO VARIABLES.
ALGORITHM
Step 1: start
Step 2: read a,b
Step 3: print value of a and b before swapping
Step 4: Swap the value by :
a=a+b;
b=a-b;
a=a-b;
Step 5: print value of a and b after swapping
Step 6: stop
FLOWCHART
start
read a,b
a=a+b
b=a-b
a=a-b
stop
Q6:WRITE A PROGRAM THAT CHECKS WHETHER THE
TWO NUMBERS ENTERED BY THE USER ARE EQUAL
OR NOT.
ALGORITHM
Step 1: start
Step 2: read num1,num2
Step 3: if (num1==num2), print both entered numbers
are equal otherwise print entered numbers are
unequal.
Step 4: stop
FLOWCHART
start
read num1,num2
num1=
=num2
print num2
Is not equal print num1
to num1 Is equal to
num2
stop
Q7:WRITE APROGRAM TO FIND GREATEST OF THREE
NUMBERS.
ALGORITHM
Step 1: start
Step 2: read num1,num2,num3
Step 3: if (num1>num2)&&(num1>num3)
print num1 is greatest;
if (num2>num1)&&(num2>num3)
print num2 is greatest;
if (num3>num1)&&(num2>num2)
print num3 is greatest;
Step 4: stop
FLOWCHART
start
(num1>num2)&&(nu
TRUE
m1<num3)
FALSE
FALSE
STOP
STOP
Q8:WRITE A PROGRAM THAT FINDS WHETHER A
NUMBER IS EVEN OR ODD.
ALGORITHM
Step 1: start
Step 2: read num
Step 3: if (num%2==0), print entered number is even
Otherwise odd;
Step 4: stop
Flowchart
Q9:WRITE A PROGRAM THAT TELLS WHETHER A
GIVEN YEAR IS A LEAP YEAR OR NOT.
ALGORITHM
Step 1: start
Step 2: read year
Step 3: if (year%400==0) || (year%4==0 &&
year%100!=0), print year given is a leap
year; Otherwise print given year is not a
leap year
Step 4:stop
Flowchart
Q10:WRITE A PROGRAM THAT ACCEPTS MARKS OF
FIVE SUBJECTS AND FINDS PERECNTAGE AND PRINTS
GRADE .
ALGORITHM
Step 1: start
Step 2: read m1,m2,m3,m4,m5,per
Step 3: per=((m1+m2+m3+m4+m5)*100)/500);
Step 4: if (per>=90)
print secured % with grade A;
if (per>=80 and per<90)
print secured % with grade B;
if (per>=60 and per<80)
print secured % with grade C;
else print secured % with grade D;
Step 5: stop
FLOWCHART
Q11:WRITE A PROGRAM THAT TAKES TWO
OPERANDS AND ONE OPERATOR FROM THE USER
AND PERFORM THE OPERATION AND PRINTS RESULT
BY USING SWITCH STATEMENT.
ALGORITHM
Step 1: Start
Step 2: Read num1, num2, op
Step 3: Print enter 1 for addition \n 2 for
subtraction \n 3
for multiplication \n 4 for division \n 4 for
division
\n 5 for modulo
Step 4: Switch(op)
Case 1:
Print addition of num 1 and
num2 and put break statement
Case 2:
Print subraction of num1 and num2
and put break statement
Case 3:
Print multiplication of num1
and num2 put break statement
Case 4:
Print division of num 1 and
num
and put break statement
Case 5:
Print remainder when
num 1 divide by num2 and
put break statement
Default:
Print you made a wrong choice
Step 5: Stop
FLOWCHART
start
Print num1 -
Case 2 num2
Print num1 %
Case 5
num2
You made a
default wrong choice
Stop
Q12:WRITE A PROGRAM TO PRINT SUM OF ALL
NUMBERS UPTO A GIVEN NUMBER.
ALGORITHM
Step 1: Start
Step 2: Read num,i,sum
Step 3: Initialise i=0,sum=0
Step 4: sum=sum+i;
i=i+1;
Step 5: Repeat steps 4 until (i<=num)
Step 6: Print sum of numbers
Step 7: Stop
FLOWCHART
Q13:WRITE A PROGRAM TO FIND FACTORIAL OF A
NUMBER.
ALGORITHM
Step 1:Start
Step 2:Read num and intialise fac=1 and i=1
Step 3:fac=fac*i
Step 4:i=i+1
Step 5:repeat steps 3 and 4 until (i<=num)
Step 6:print factorial of num
Step 7:stop
FLOWCHART
Q14:WRITE A PROGRAM TO PRINT SUM OF EVEN AND
ODD NUMBERS FROM 1 TO N NUMBERS.
ALGORITHM
Step 1:start
Step 2:read num and initialise -
sum_odd=0,
sum_even=0,
odd=1,
even=2;
Step 3:sum_odd=sum_odd+odd
odd=odd+2;
Step 4:sum_even=sum_even+even
even=even+2;
Step 5:repeat steps 3 and 4 until (odd<=num)
and (even<=num)
Step 6:print sum of odd and even numbers
Step 7: Stop
FLOWCHART
Q15:WRITE A PROGRAM TO PRINT FIBONACCI SERIES.
ALGORITHM
Step 1:start
Step 2:read num and initialise i=0,f1=0,f2=1 and f3=0
Step 3:print the message “Fibonacci series upto
n terms is:”
print f1
print f2
Step 4:f3=f1+f2
print f3
f1=f2
f2=f3
Step 5:repeat step 4 until (i<num-2)
Step 6:stop
FLOWCHART
Q16:WRITE A PROGRAM TO CHECK WHETHER THE
ENTERED NUMBER IS PRIME OR NOT.
ALGORITHM
Step 1:start
Step 2:read num and initialise count=0 and i=1
Step 3: if (num%i==0), then do Count =count+1
Step 4:repeat step 3 until (i<=num)
Step 5:if (count ==2), Print it is a prime number Otherwise
print it is not a prime
Step 6: Stop
FLOWCHART
Q17:WRITE A PROGRAM TO FIND THE SUM OF DIGITS
OF THE ENTERED NUMBER.
ALGORITHM
Step 1:start
Step 2:read n, num and initialise rem=0 , sum=0
Step 3: rem=num% 10
Sum = rem+ sum
num = num/10
Step 4:repeat step 3 until (num>0)
Step 5:print the sum of digits
Step 6:stop
FLOWCHART
Q18:WRITE A PROGRAM TO FIND REVERSE OF A
NUMBER.
ALGORITHM
Step 1: start
Step 2: read n, num,rev and initialise -
rem=0;
rev=0 ;
n=num;
Step 3:rem=num%10
rev = rem +rev*10
num = num/10
Step 4:repeat step 3 until (num>0)
Step 5:print the reverse of number
Step 6:stop
FLOWCHART
Q19:WRITE A PROGRAM TO PRINT ARMSTRONG
NUMBERS FROM 1 TO 1000.
ALGORITHM
Step 1:start
Step 2:print the message “all Armstrong numbers between 1
and 1000:”
Step 3:read n=1
Step 4: if (n<=9),
print n Otherwise
Step 5:initialise digit =intlog10(num+1)
Rem=num%10
sum=sum+pow(rem,digit)
num=num/10
Step 6:repeat previous step until num>0
Step 7:repeat previous step until n<1000
Step 8:stop
FLOWCHART
Q20:WRITE A PROGRAM TO CONVERT DECIMAL
NUMBER TO BINARY NUMBER AND VICE VERSA.
ALGORITHM
Step 1:start
Step 2:read num,n,rem,dec,bin,ch and
initialise base =1
Step 3:print enter 1 to perform binary
conversion and enter 2 for decimal
conversion
Step 4:if (ch=1)
enter the decimal number-n=num
Step 5:rem=num%2
bin=bin+rem*base
num=num/2
base=base*10
Step 6:repeat previous step until (num>0)
print binary remainder
Step 7:else if (ch==2)
enter the binary number-
n=num
Step 8:rem=num%10
dec=dec+rem*base
num=num/10
base=base*2
Step 9:repeat previous step until (num>0)
Step 10:print the decimal number
Step 11:stop
FLOWCHART
start
n=num rem=num%2
dec=dec+rem*base
num=num/2
num>0 base=base*10
Print binary
number
rem=num%10
dec=dec+rem*bas
e
num=num/10
base=base*2
FLOWCHART
Q22:WRITE A PROGRAM THAT TAKES INPUT OF
TWO ARRAYS AND SAVES SUM OF
CORRESPONDING ELEMENTS OF THESE ARRAYS
IN A THIRD ARRAY AND PRINTS THEM.
ALGORITHM
Step 1:start
Step 2:read a[50],b[50],c[50],i,size and
initialise sum=0
Step 3:intialise i=0
Step 4:enter the element at arr[i] for array 1
and array 2 ,c[i]=a[i]+b[i] and print the
elemet of array 1 and array 2
Step 5:increment i by 1
Step 6:repeat step 4 and 5 until (i<size)
Step 7:stop
FLOWCHART
start
i=0
i<size
i<size
stop
Q23:WRITE A PROGRAM TO FIND MAXIMUM
AND MINIMUM ELEMENT OF ARRAY.
ALGORITHM
Step 1:Start
Step 2:Read a[50],size,i and initialise max=0,min=0
Step 3:Initialise i=0
Step 4:Enter the element at a[i],increment i by 1
Step 5:Repeat step 4 until (i<size)
Step 6:max=a[0] and min=a[0]
Step 7: if(max<a[i]),then store max=a[i] and
if(min<a[i]),then store min=a[i]
Step 8:Repeat step 7 until (i<size)
Step 9:Print the maximum and minimum
values of given array
Step 10:Stop
FLOWCHART
START
Enter the
i<size element at a[i]
max=a[0]
min=a[0]
i=0
i<size
max<a[i] max=a[0]
min>a[i] min=a[0]
stop
24. WAP TO SEARCH AN ELEMENT IN AN ARRAY
USING LINEAR SEARH.
ALGORITHM
Step 1:Start
Step 2:Declare array[] and variables i=0 and result ,x
Step 3:Input the elements of array and enter the
number to be searched
Step 4: If(array[i]==x), return i otherwise return -1
Step 5:If result==-1
Print element not
found
Else
Print element at index i
Step 6:Stop
FLOWCHART
START
READ array[],n,x,result
result=search(array,n,x)
stop
search(array,n,x)
i<n
array[i]==x return i
return -1
stop
25: WRITE A PROGRAM TO SORT THE ELEMENTS OF THE ARRAY
USING THE BUBBLE SORTING TECHNIQUE.
ALGORITHM
Step 1:Start
Step 2:bubblesort(array)
Step 3:enter the number of elements
Step 4:now starting with the first element index
compare the current element with the next
element of the array
Step 5:if the current element is greater than the
next element of the array ,swap them
Step 6: if the current element is less than the
next element move to the next element
Step 7:repeat the previous steps until the
sorted array is obtained
Step 8:print the sorted array
Step 9:stop
FLOWCHART
start
int array[20],n,num,i
i=i+1
i<n
num=bubblesort(array,n)
stop
bubblesort(array,n)
int i=0
i=i+1
i<n
int j=0
j=j+1
j<n
array[j]
<array[j
array[j]=array[j+1]
array[j+1]=temp
26:WRITE A PROGRAM TO ADD AND MULTIPLY TWO MATRICES OF
ORDER nXn.
ALGORITHM
Step 1:start
Step 2:read a[5][5],b[5][5],c[5][5],d[5][5],i,j,k,rc1 and
initialise sum=0
Step 3:enter the elements of matrix 1 and matrix 2
as
number of times the the number of rows and
columns of matrix is given
Step 4: i=0 and j=0,sum=0 and k=0
sum=sum+a[i][k]*b[k][j] until (k<rc1) and
c[i][j]=sum
Step 5:repeat step 4 until (i<rc1) And (j<rc1)
Step 6:i=0 and j=0
d[i][j]=a[i][j]+b[i][j] until (j<rc1) and (i<rc1)
Step 7:print the matrix obtained after addition and
multiplication.
Step 8:Stop
FLOWCHART
Start
read a[5][5],b[5][5],c[5][5],d[5][5],i,j,k,rc1
and initialise sum=0
int i=0,j=0
i<rc1
j<rc1
d[i][j]=a[i][j]+b[i][j]
i<rc1
j<rc1
sum=0
K<rc1
FLOWCHART
Start
i<rc
j<rc
i<rc
j<rc
i==j
trace=trace+a[i][i]
Print trace
stop
28:WRITE A PROGRAM TO IMPLEMENT strlen(),strcpy() and
strcat().
ALGORITHM
Step 1:Start
Step 2:Read string[50],dest[50],c1[50]
Step 3:Print the length of string is strlen(string)
Step 4:strcpy(dest,string)
Step 5:print the value at source is string
Step 6:print the value at destination is dest
Step 7:strcat(string,c1)
Step 8:print the concatenated string is string
Step 9:stop
FLOWCHART
START
Read string[50],dest[50],c1[50]
strcpy(dest,string)
strcat(string,c1)
stop
29:WRITE A PROGRAM TO SWAP TWO ELEMENTS
USING THE CONCEPT OF POINTERS.
OUTPUT
ALGORITHM
Step 1:start
Step 2:read x,y,*ptr1,*ptr2,*ptr3;
Step 3:Enter the value of x and Enter the value of y
Step 4: ptr1=&x;
ptr2=&y;
Step 5:print The value of x and y before swapping
Step 6: ptr3=ptr1;
ptr1=ptr2;
ptr2=ptr3;
Step 7:printf The value of x and y after swapping
Step 8:stop
FLOWCHART
START
read x,y,*ptr1,*ptr2,*ptr3
ptr1=&x
ptr2=&y
ptr3=ptr1
ptr1=ptr2
ptr2=ptr3
stop
30: Define a structure data type TRAIN_INFO. The type
contain Train No.: integer type Train name: string Departure
Time: aggregate type TIME Arrival Time : aggregate type
TIME Start station: string End station : string The
structure type Time contains two integer members: hour
and minute. Maintain a train timetable and implement the
following operations: (i)List all the trains (sorted according
to train number) that depart from a particular section.
(ii)List all the trains that depart from a particular station at a
particular time. (iii)List all he trains that depart from a
particular station within the next one hour of a given time.
(iv)List all the trains between a pair of start station and
end station.
ALGORITHM
Step 1:start
Step 2:define structure train along with its members
Step 3:read i,n,j,arr[10],h,m,station[20],bstation[20]
Step 4:enter the information of train
Step 5:enter the various details regarding the
train until (i<n)
Step 6:if (n==tr[i].departhour and m==tr[i].departmin)
print the train number otherwise print no
trains are departed at this time
Step 7:sort the train information with respect to
train no and print the sorted details i.e
the train no.
Step 8: if(station==tr[i].end_station), print train
number is found otherwise print train no
is not found.
Step 9: if(station==tr[i].end_station and
station==tr[i].start_station)
print train is found between these
station otherwise print no train is found
between these stations
Step 10: repeat these steps until (i<n)
Step 11: Stop
FLOWCHART
START
Read I,n,j,h,m,station[20],bstation[20]
i<n
if n==tr[i].departhour
and tr[i].departmin Print train number
if
station==tr[i].end_stati Print train is found
on==tr[i].start_station between these station
st
Print train is not found between these station op