UNIT-1 C Programming
UNIT-1 C Programming
Step 1: Start
Step 5: End
What is a Program?
A program is a set of instructions a computer follows to perform a specified
task. Many programming languages can be used to write computer programs.
Some popular programming languages include Python, Java, C+
+, JavaScript, PHP, and Ruby. These high-level programming languages are
human-readable and writable. These languages are converted into low-level
machine languages by compilers, interpreters, and assemblers within the
computer system.
A program tells the computer how to accept input, manipulate that input, and
display the output in some form that humans find useful.
The input will be the characters you type from the keyboard
The program will format the text and correct the spelling
Well-organized will be displayed on the screen as output
Algorithm vs Program: Difference Between Program and
Algorithm
Computer algorithms solve the problem while computer programs
implement them in a form that a computer can execute. Here are the
main differences between algorithms and programs :
Algorithm Program
2. Problem Analysis:
Input(s) to the problem, their form and the input media to be used
Output(s) expected from the problem, their form and the output media to
be used
Special constraints or conditions (if any)
Any formulas or equations to be used
6. Debugging and Testing: A written program may have errors, some errors
can be detected by the language compilers and some errors can not be
identified by the compiler and occured during the program run. Common types
of errors are
So testing is the process of checking the program for its correct functionality by
executing the program with some input data set and observing the output of
the program.
7. Documentation: From the start of the problem solving to the end of the
implementation of the program, all the tasks should be documented i.e. kept
for future reference. It is also the important part of the problem solving or
program development. Documentation may be of two types
What data is available or needed to help clarify, or fully understand the problem?
Is it a top priority to resolve the problem at this point in time?
Are additional resources required to clarify the problem? If yes, elevate the problem
to your leader to help locate the right resources and form a team.
Consider a Lean Event (Do-it, Burst, RPI, Project).
∙Ensure the problem is contained and does not get passed to the next process step.
Generate a list of actions required to address the root cause and prevent
problem from getting to others.
Assign an owner and timeline to each action.
Status actions to ensure completion.
Step 6: Execute Action Plan
High-Level Design
declare two integers
scan the values from the user
call addition
call subtraction
call multiplication
call division
addition, subtraction, multiplication, division are sub functions.
int main()
{
int a,b;
add(a,b);
sub(a,b);
mul(a,b);
div(a,b);
return 0;
}
A) For some algorithms, all the cases (worst, best, average) are asymptotically the
same. i.e., there are no worst and best cases.
Example: Merge Sort does Θ(n log(n)) operations in all cases.
B) Where as most of the other sorting algorithms have worst and best cases.
Example 1: In the typical implementation of Quick Sort (where pivot is chosen as a
corner element), the worst occurs when the input array is already sorted and the
best occurs when the pivot elements always divide the array into two halves.
Example 2: For insertion sort, the worst case occurs when the array is reverse
sorted and the best case occurs when the array is sorted in the same order as
output.
Examples with their complexity analysis:
1. Linear search algorithm:
C
C++
Java
Python3
C#
PHP
Javascript
// otherwise return -1
int i;
if (arr[i] == x)
return i;
return -1;
/* Driver's code*/
int main()
{
int arr[] = { 1, 10, 30, 15 };
int x = 30;
// Function call
search(arr, n, x));
getchar();
return 0;
Output
30 is present at index 2