Monday, 1 September 2014
Algorithms and Flowchart
Algorithms and Flowchart
Algorithms
To make a computer do anything, you have to write a computer program. To write a computer program, you have to tell the computer, step by step, exactly what you want it to do. The computer then "executes" the program, following each step mechanically, to accomplish the end goal.
When you are telling the computer what to do, you also get to choose how it's going to do it. That's where computer algorithms come in. The algorithm is the basic technique used to get the job done. Let's follow an example to help get an understanding of the algorithm concept.
Let's say that you have a friend arriving at the airport, and your friend needs to get from the airport to your house. Here are four different algorithms that you might give your friend for getting to your home:
The taxi algorithm:
- Go to the taxi stand.
- Get in a taxi.
- Give the driver my address.
The call-me algorithm:
- When your plane arrives, call my cell phone.
- Meet me outside baggage claim.
The rent-a-car algorithm:
- Take the shuttle to the rental car place.
- Rent a car.
- Follow the directions to get to my house.
The bus algorithm:
- Outside baggage claim, catch bus number 70.
- Transfer to bus 14 on Main Street.
- Get off on Elm street.
- Walk two blocks north to my house.
All four of these algorithms accomplish exactly the same goal, but each algorithm does it in completely different way. Each algorithm also has a different cost and a different travel time. Taking a taxi, for example, is probably the fastest way, but also the most expensive. Taking the bus is definitely less expensive, but a whole lot slower. You choose the algorithm based on the circumstances.
In computer programming, there are often many different ways -- algorithms -- to accomplish any given task. Each algorithm has advantages and disadvantages in different situations. Sorting is one place where a lot of research has been done, because computers spend a lot of time sorting lists. Here are five different algorithms that are used in sorting:
- Bin sort
- Merge sort
- Bubble sort
- Shell sort
- Quicksort
If you have a million integer values between 1 and 10 and you need to sort them, the bin sort is the right algorithm to use. If you have a million book titles, the quicksort might be the best algorithm. By knowing the strengths and weaknesses of the different algorithms, you pick the best one for the task at hand.
Here are some interesting links:
- A sequential solution of any program that written in human language,called algorithm.
- Algorithm is first step of the solution process, after the analysis of problem, programmer write the algorithm of that problem.
- Example of Algorithms:
Q. Write a algorithem to find out number is odd or even?
Ans.
step 1 : start
step 2 : input number
step 3 : rem=number mod 2
step 4 : if rem=0 then
print "number even"
else
print "number odd"
endif
step 5 : stop
Flowchart
1. Graphical representation of any program is called flowchart.
2. There are some standard graphics that are used in flowchart as following:
| Figure: Start/Stop terminal box |
| Figure: Input/Output box |
| Figure: Process/Instruction box |
![]() |
| Figure: Lines or Arrows |
![]() |
| Figure: Decision box |
![]() |
| Figure: Connector box |
| Figure: Comment box |
![]() |
| Figure: Preparation box |
![]() |
| Figure: Separate box |
Q. Make a flowchart to input temperature, if temperature is less than 32 then print "below freezing" otherwise print "above freezing"?
Ans.
![]() |
| Figure: Flowchart example of C program |
Your average Pakistani boy in a not so average endless runner! Guide Sheeda as he saves his beloved chicken from a butcher who dreams only of making a tikka soup out of it.
Proudly made in Pakistan
Square number program and flowchart
Square number program and flowchart
Q. Write a C program to accept a number from user and print the square of number. Also draw the flowchart of program.
Ans.
/*c program to calculate the square of number*/
#include<stdio.h>
int main()
{
double n,z;
printf("Enter any number : ");
scanf("%lf", &n);
z = n * n;
printf("Square of number %lf*%lf = %lf",n,n,z);
return 0;
}
The output of above program would be:
Enter any number : 25
Square of number 25*25 = 625
Flowchart of above C square number program:
Ans.
/*c program to calculate the square of number*/
#include<stdio.h>
int main()
{
double n,z;
printf("Enter any number : ");
scanf("%lf", &n);
z = n * n;
printf("Square of number %lf*%lf = %lf",n,n,z);
return 0;
}
The output of above program would be:
Enter any number : 25
Square of number 25*25 = 625
Flowchart of above C square number program:
![]() |
| Figure : Flowchart for square number C program |
To make a computer do anything, you have to write a computer program. To write a computer program, you have to tell the computer, step by step, exactly what you want it to do. The computer then "executes" the program, following each step mechanically, to accomplish the end goal.
When you are telling the computer what to do, you also get to choose how it's going to do it. That's where computer algorithms come in. The algorithm is the basic technique used to get the job done. Let's follow an example to help get an understanding of the algorithm concept.
Let's say that you have a friend arriving at the airport, and your friend needs to get from the airport to your house. Here are four different algorithms that you might give your friend for getting to your home:
The taxi algorithm:
- Go to the taxi stand.
- Get in a taxi.
- Give the driver my address.
The call-me algorithm:
- When your plane arrives, call my cell phone.
- Meet me outside baggage claim.
The rent-a-car algorithm:
- Take the shuttle to the rental car place.
- Rent a car.
- Follow the directions to get to my house.
The bus algorithm:
- Outside baggage claim, catch bus number 70.
- Transfer to bus 14 on Main Street.
- Get off on Elm street.
- Walk two blocks north to my house.
All four of these algorithms accomplish exactly the same goal, but each algorithm does it in completely different way. Each algorithm also has a different cost and a different travel time. Taking a taxi, for example, is probably the fastest way, but also the most expensive. Taking the bus is definitely less expensive, but a whole lot slower. You choose the algorithm based on the circumstances.
In computer programming, there are often many different ways -- algorithms -- to accomplish any given task. Each algorithm has advantages and disadvantages in different situations. Sorting is one place where a lot of research has been done, because computers spend a lot of time sorting lists. Here are five different algorithms that are used in sorting:
- Bin sort
- Merge sort
- Bubble sort
- Shell sort
- Quicksort
If you have a million integer values between 1 and 10 and you need to sort them, the bin sort is the right algorithm to use. If you have a million book titles, the quicksort might be the best algorithm. By knowing the strengths and weaknesses of the different algorithms, you pick the best one for the task at hand.
Here are some interesting links:
Sunday, 31 August 2014
Draw the flowchart diagram for check a number is prime number or not.
Q. Draw the flowchart diagram for check a number is prime number or not.
Tuesday, 4 March 2014
programming solutions: SORTING programms
programming solutions: SORTING programms: //BUBBLE SORT USING C PROGRAM #include<stdio.h> int main(){ int s,temp,i,j,a[20]; printf("Enter total numbers of elem...
programming solutions: 10:ARRAY programms
programming solutions: 10:ARRAY programms: // FIND OUT LARGEST NUMBER IN AN ARRAY USING C PROGRAM #include<stdio.h> int main(){ int a[50],size,i,big; printf("\nE...
programming solutions: Area and volume
programming solutions: Area and volume: //C PROGRAM TO CALCULATE AREA OF A CIRCLE #include <stdio.h> #define PI 3.141 int main(){ float r, a; printf("Radius:...
Subscribe to:
Posts (Atom)







