Professional Documents
Culture Documents
CHAPTER -1
1. COMPUTER Is a well trained dogs which responds to specific set of predetermined set of
commands
5. to run a program we need a compiler to translate the written program to the machine level
programming and check for any errors.
5. In unix execuatable file will have output of form .out but in windows either .c or .exe
Installing c
First program
1. # include<stdio.h>
# preprocessor
include directive
stdio.h header file
in this program we are dealing with include directive, when a preprocessor indicate the directive it
replace the directory with the content of the file with name stdio.h. the content does not change in
source file once the file is compiled it restores.
In another words, Include directive. Many programming languages and other computer files have a
directive,often called include (as well as copy and import ), that causes the contents of a second
file to be inserted into the original file. These included files are called copybooks or header files.
Let say we have a program puts(my name is meera) and we are trying to run this line, we does
not know if put is a valid command or not. Preliminary information about some commands for the
compiler to run is stored in .h files which are known as header files.
2. Blocks:
With respect to the diagram of the box let us ask some questions
int main(void)
Answers
1. the result of the function is the integer
2. our function block is the main
3. function does not require any function parameters which is void.
After function block is initialised it does not intend to anything, if we have {} of the body which
indicates that the function is intended to do something we call it as function body, function main
body is what it has to do in previous example puts(my name is meera) ; puts is a function
invocation.
Note: All function must end with the semicolon and function invocation should be enclosed in
( and )
when the function body is performing its task, the main function is suspended are made to sleep,
after the execution of the function body it returns to the main function.
1. return 0; denote the end of function execution and it should be within the function body. And it
indicates the program worked fine.
decimal to octal
octal to decimal
Print f
1. To store the operation we need a container known as the variable as from the name we cld
understand that it varies over the program. Variables can be a upper or lower case or a number but it
should begin with a alphabets and we can use underscore also.
2. How to define a variable???? it does by simple declaration for eg int a , b so the value of a and b
should be an integer.
A =1 (assignment )
The above statement reads: assign a value of 1 to a variable named a or a bit shorter assign
1 to a.
3. In c programming we do have specific keywords which are predefine words we could not
use a variable but u can change the sensitivity of the character.
Floating point:
Operators
1. division in c / dividend/divisor
2. remainder operator int i, j, k ; k = i %j for eg let i = 15 j = 5 ; remainder is 0
3. * / % have the same order of precedence so to calculate the expression we use the concept of
binding we performs operation from left to right this is possible only if the operators has
same hierarchy.
4.
For example
int sheep;
sheep = 0;
sheep = sheep +1;
in this example, we can find initially the value of sheep 0, then it becomes 1, 2,
3.
Which in short we can write in c programming as
Sheep ++
Similarly for decrement we use
1. i = i +1 i++;
2. i = i+2*j i+ = 2* j;
3. var = var/2 var / = 2;
CHARACTER:
Character are single letter in simple meanings , the char is the command used for assigning the
character; ASCII uses the specific number for different letter.
Characters should be enclosed by the single quotes
Important: char \ , is used as the escape command , \ n new lines escapes in to line \ r return to the
beginning of the line, \a alarm u will hear a beep sound \ 0 null
Conditional Instructions
1. we do come across the certain situation we have a condition is true execute the statement
such conditional clause in C programming is define by
1. if condtion
2. If else condition
If statement
if (the sheep >=120)
{
Makeabread
Eat
Shower
}
When multiple execution is to be made it enclosed with the curly braces
Input and Output
1. Now to understand the connectivity between the computer and the outside world.
2. eg : puts function could not be used to print the integer as it print only the string character.
because using this command in the input coding, would display the corresponding material at the
output screen.
3.Printf command for printing all type of characters.
Its is a decimal point of type integer values = printf( %d/n, sheep count) %x is hexadecimal
number %i integer, % o = octal number, %c character; % f float; %% displays percentage sign.
% d = are called specifiers
Sheep count = arguments
VarFloat = 3.1415 ;
print("The year is %d. The radius is denoted as %c while PI is
equal to %f", VarInt, VarChar, VarFloat);
return 0;
4. scanf command is used to get the information from the user scanf (%d, &sheep count) and &
represent the laoction of the place of the variable name
int main(void)
{
int value,square; Print f displays the information to
print("Give me a number and I will square it!\n"); get the values from the user.
scanf("%d", &value);
Using scanf statement we are
square = value * value;
getting the value of a number from
print("You've given %d\n",value);
the user which should be a
print("The squared value is %d\n",square); decimal with the variable name
return 0; value
}
5. Sqrt is the function used to obtain the square root of the value, to obtain the mathematical
directory use math.h
CHAPTER 3
CONDITIONAL STATEMENT
For the if else statement, for the multiple instruction we use the blocks, blocks are noting but that
follows a curly brace for the condition.
If the weather is fine, well go for a walk. If we find a nice restaurant, well have lunch there.
Otherwise, well eat a sandwich. If the weather is poor, we'll go to the theater. If there are no
tickets, well go shopping in the nearest mall.
If (weather is fine)
go for the walk();
If (find nice restaurant)
Have lunch();
Nested if
Else
eat sandwich();
else
If (ticket available)
go to the theatre();
else
go to the shopping();
I. Integers
To specify the memory requirement for the data types we use the command known as modifiers
1. Long and short could not be used with char like long char etc;
I. Float
1. Long
2. Short cannot be used with float
3. Double
4. Unsigned cannot be used along with floats
Since because adding the long and short float could actually results in neglecting some values, we
cannot perform adding or subtracting the number of floats.
data of type char or short int will be converted to type int (this is called an integer
promotion);
if there is any value of type float in the expression, the other data will be converted to float;
if theres any value of type double in the expression, the other data will be converted to
double;
if theres any value of type long int in the expression, the other data will be converted to
long int.
1. Explicit conversion is made by using the type command, type is double in the following case
float x;
double y;
y = (double) x; (type) value;
if(number3>max)
max = number3
print(the largest number is %d, max)
return 0;
return 0;
if obtain the statement once but while statement continues until the statement becomes true
LOOPS
Ability to perform the certain number of loops repeatedly in a program is
While
Do while
For loop
WHILE
1. If we want to do something for the certain number of times is done using while loop
While statement check the condition before executing the if or for loop, if the condition
become false it will not enter the loop
2. Do Loop: The condition is checked at the end of the loop, loop body is executed atleast once if
the condition is not met,
do
statement;
while(condition);
do {
statement_1;
statement_2;
:
:
statement_n;
} while(condition);
3. For loop.
Initialisation;
While (checking condition) {
Modification
}
Can be modified as
For( i=0; i < 100; i++); if any of three condition is missing it assumes to be 1 and the condition
statement is assume to be true in which it has infinite loops never ending loops to be not true it
assume to be true. All the three condition should be separated by semi colons.
Multiple initialisation and increment can be done in for loop for eg for ( i=0 j= 1; i <=2; i++) it
has 2 initialisation such as i=0 and j=1 however only one initialisation is done.
ODD LOOPS
1. When are initiating writing a program, beforehand we are not unaware to know the how
much input should be given for the particular condition, we do use odd loop for example
# include<stdio.h>
Int main()
{
Int num;
Printf(enter the number to be squared);
Scanf(%d, &num);
printf(the square %d of the number is %d\n,num , num*num);
printf(want to square another number y/n);
fflush(stdin);
scanf(%c, &another);
Return 0;
The control statement that allow us to decide from the number of choices is called switch.
Int main()
{
Char c = x;
Switch( c)
{
Case v
Printf( I m in case v\n)
Case x
Printf( I m in case x\n)
}
1. In switch we can have only int and char constant, Even float is not allowed.
2. We can check the value of the expression in a switch and break is necessary after each case
condition.
3. Cases can never have a variable expression like case 1+2 its illegal
4.
Computer logic
2. Connection of condition are called conjuction and logical conjuction in c is && (and)
3. Either one of the condition is true is disjunction or logical disjunction in c is | | or
4. If the condition is true if use this ! it turns out to be false and vice versa.
5. From the De Morgan Law,
The negation of the conjuction is the disjunction of the negation (p && q) = = ! p | | !q
the negation of the disjunction is the conjuction of the negation ! (p || q) == !p && !q