Professional Documents
Culture Documents
DEFINITION OF PROGRAMMING:
A vocabulary and set of grammatical rules for instructing a computer
to perform specific tasks.
These instruction can be high level languages or low level languages.
But now these terms programming languages usually refers to highlevel languages, such as BASIC, C, C++, COBOL, FORTRAN, and Pascal. Each
language has a unique set of keywords (words that it understands) and a
special syntax for organizing program instructions.
High-level programming languages, while similar compared to human
languages, and simpler than the languages the computer actually
understands, called machine languages.
Programming Fundamentals
COMPILER:
Compiler translate the whole program into machine language.
It makes a file called Object File (Machine oriented File)
It shows the error list at the end of compilation.
INTERPRETER:
Interpreter reads the instruction line by line.
It convert the code into machine after execute.
If any error occurs then interpreter stop and show the errors.
1) Integers Values:
Integer values are the numeric constants numbers without any fractional
part or exponential part.
There are two types of integers in C language:
TYPE
SHORT INT
LONG INT
MEMORY
2 BYTES
4 BYTES
RANGE
-32768 to +32767
-231 to +231 -1
Programming Fundamentals
Floating Values:
Floating point values are the numeric constants that has either fractional
form or exponent form.
TYPE
FLOAT
DOUBLE
LONG DOUBLE
MEMORY
RANGE
10 to 1038
10-308 to 10308
Same as Double, but
have some special
features
-.38
4 BYTES
8 BYTES
10 BYTES
Character:
Character are the constant which use single quotation around characters.
For example: 'a', 'U', 'Z', 'b' etc.
ESCAPE SEQUENCE:
\n
\t
\b
\r
\f
\
\
\\
New Line
Tab
Backspace
Carriage Return
Formatted
Single Quote
Double Quotes
Backslash
LOOPS:
In computer programming, a loop is a sequence of instruction s that is
continually repeated until a certain condition is reached. Typically, a certain
process is done, such as getting an item of data and changing it, and then
some condition is checked such as whether a counter has reached a
prescribed number.
1) FOR LOOP:
Expression:
for (initialization statement; test expression; update statement) {
Code/s to be executed;
}
Programming Fundamentals
Flow Chart:
Example 01:
Print Hello World Ten Times:
#include<stdio.h>
int main()
{
int i;
for (i = 0; i < 10; i++)
{
printf ("Hello\n");
printf ("World\n");
}
return 0;
}
Example 02:
Write a program to find the sum of first n natural numbers where n is
entered by user. Note: 1,2,3... are called natural numbers.
#include <stdio.h>
int main(){
4
Programming Fundamentals
2) WHILE LOOP:
Expression:
while (test expression) {
Statement/s to be executed.
}
Flow Chart:
Programming Fundamentals
Example 03:
#include<stdio.h>
int main()
{
int counter, howmuch;
scanf("%d", &howmuch);
counter = 0;
while ( counter < howmuch)
{
counter++;
printf("%d\n", counter);
}
return 0;
}
Example 04:
#include<stdio.h>
int main(void) {
int i;
i = 0;
while(i++ < 5) {
printf("%d\n", i);
}
printf("\n");
i = 0;
while(++i < 5) {
printf("%d\n", i);
}
return 0;
}
3) DO WHILE LOOP:
Expression:
6
Programming Fundamentals
do {
Some code/s;
}
while (test expression);
Flow Chart:
Example 05:
Write a C program to add all the numbers entered by a user until user
enters 0.
Programming Fundamentals
{
printf("Enter a number\n");
scanf("%d",&num);
sum+=num;
}
while(num!=0);
printf("sum=%d",sum);
return 0;
}