Sie sind auf Seite 1von 22

EMANUEL IN THE

BEGINNING ∞Ωµ

Advantages of C Comment [L1]: Advantages of C

C is Portable
This means a program written for one computer may run successfully on other
computer
also.
C is fast
This means that the executable program obtained after compiling and linking runs
very fast.
C is compact
The statements in C Language are generally short but very powerful.
Simple / Easy
The C Language has both the simplicity of High Level Language and speed ofLow
Level Language. So it is also known as Middle Level Language
C has only 32 Keywords
C Compiler is easily available
C has ability to extend itself. Users can add their own functions to the C Library

Definition of Algorithms OR What are Algorithms


Definition of Algorithms OR What are Comment [L2]: Definition of Algorithms

Algorithms
Algorithms are used to solve a problem step by step using english
language. It is the part of software designing. An algorithm defines as
the step by step procedure or method that can be carried out for
solvingprogramming problems. An algorithm tells computer that how to
solve problem systematically to get desired output. Mainly we follow
following steps to design an algorithm.
Step 1 - START
It represents beginning of the algorithm.
Step 2 - DECLARE
The variables used in algorithm are declared in this step.
Step 3 - INPUT
Here we input the values
Step 4 - FORMULA
The required result is generated in this step.
Step 5 - OUTPUT
It displays the output or result.
Step 6 - STOP
It is an end of Algorithm

ARRAYS Comment [L3]: ARRAYS

Arrays are widely used data type in ‘C’ language. It is a collection of elements of
similar data type. These similar elements could be of all integers, all floats or all
characters. An array of character is called as string whereas and array of integer or
float is simply called as an array. So array may be defined as a group of elements that
share a common name and that are defined by position or index. The elements of an
arrays are store in sequential order in memory.
WAP to input your name and display it
#include
void main ( )
{
char nm [15];
clrscr ( );
printf (“enter your name”);
gets (nm);
printf (“name is %s”,name);
getch ( );
}

CHARACTER SET Comment [L4]: CHARACTER SET

A character contains any alphabet, digit or special symbol to represent information.


The set or character which is valid in C program is called character set. The set
includes some graphic characters. Graphic characters contain alphabets, digits and
some special symbols. C language uses case letters (a to z), the digit (0 to 9) and
certain special characters like constants, variables, operators etc. and some special
symbols:- $, <, >, <=, =, !, # etc.
Non graphical character sets contain white spaces these are also called escape
sequences.

CONSTANTS Comment [L5]: CONSTANTS

A constant represents that what a value is stored in it cannot be changed anytime. We


use “const” keyword for declaring any variable as constant. This keyword is a
guideline to a compiler that the value of variable is not changeable at any time during
the execution of the program.

CONTROL STATEMENTS Comment [L6]: CONTROL STATEMENTS

These statements are used to control the flow of program by using these statements.
We can jump from one statement to another statement in C language. We can have
four types of control statements:-
1. decision making
2. case control statement or switch statement
3. looping / iteration statement
4. jump / branching statement
These statements are used when we want to take any decision according to the
condition or user requirement. These statements work on a particular condition.
These conditions are used by using ‘if’ statement. We can have four types of
conditional statements
1. if
2. if-else
3. if – else if
4. nested if
if
if statement is simple decision making statement, which is used to take any decision
when the condition is true.
if (statement)
{
Statement;
}
if (expression / condition)
Statement;
If-else
This statement is used to make decision in C language. If the given condition is true
then the cursor will move to the true portion else it will move to the false portion.
if (condition)
{
Statement;
}
else
{
Statement;
}
If else-if
This is another control statement which is used to take any decision according to the
given condition. If the condition is true then the cursor will move to the true portion
and if the condition is false the cursor will move to the false or else-if portion and
then checks another condition. If this condition is true then it will move and run the
second true portion and if the condition is false then cursor will move the next
portion
of if condition which is another else-if or else portion.
if (condition)
{
Statement;
}
else if (condition)
{
Statement;
}
else if (condition)
{
Statement;
}
else
{
Statement;
}

DATA TYPES Comment [L7]: DATA TYPES

Data types can be represented in variety of ways in any programming language, so


that we can store data in system. C language provides us the way to hold any type of
data in it. It is called data type. In C language data types are classified into two
categories:-
1. Fundamental data type
2. Derived data type
Fundamental data type
These can be represented on the particular machine and these are provided by every
language because without using data types we can’t save our data and can be called
as
storage media.

Derived data type


These are those data types which are consisting of combination fundamental data
types

DECLARE ARRAYS Comment [L8]:


DECLARE ARRAYS
1. An array must be declared with type of variable or data type
2. An array contains same type of data
e.g. – int a [10]
3. The name of array cannot be same as that of any other variable within the
function.
4. The size of array is specified using sub-script notation (index)
5. THE sub-script indicates that how many elements are to be allocated to an
array.
6. A sub-script used to declare an array is called dimension

Definition of Variables Comment [L9]: Definition of Variables

Variable is a quantity, which my vary during program execution. Basically


variable are name given to the location in the memory of computer,
where different constants are stored. If a program works on some variables
then we need to declare these variables with the help of data types
DFUNDAMENTAL DATA TYPES Comment [L10]: DFUNDAMENTAL DATA
TYPES
Integer data type
It is a data type which is used to hold data in whole number e.g. 40, 4, 97, 80 and its
range is from -32768 to 32767. When we want to use integer data type, we have to
specify “int” keyword. It takes two bytes in memory and the conversion specifier is
%d.

Float type
This data type is used to store fractional numbers or these numbers are also called
real numbers. In simple language we can say, this data type contains decimal value
upto six decimal places. When we use decimal values to store then we can use it.
e.g. 49.797, 79718.80
it can hold either positive or negative value with or without decimal the conversion
specifier used for float is %f. the range of float is -3.4*10-38 to 3.4*1038. it consumes
4 bytes in memory.

Character data type


This data type is used to store character enclosed in a pair of single quotes. E.g. ‘A’,
‘B’, ‘a’or even a blank space can be used as a character. This data type contains one
byte on memory and the conversion specifier is %c.

STRING
We can also store number of characters in char data type within the range of -128 to
127. so when we store number of characters in char data type then it is converted
into
string data type. And we use conversion specifier %s.

Double data type


This data type is also used to store real type numbers and the keyword “double’ is
used. It can hold values upto 16 decimal places and it consumes 8 bytes of memory.
The conversion specifier is %lf. Its range is from 1.7*10-308 to 1.7*10308.

Long type
It contains whole number bigger than integer value is much bigger than integer. It
consumes 4 bytes of memory and its range is from -2147483648 to 2147483647. Its
conversion specifier is %l. e.g. 247894, 4774863.
This data type is used in relational operators. It gives us result in true or false. If the
output is false it returns to zero (0) and if output is true it returns to one (1). Its
range is from 0 to 1 and it has not any conversion specifier.
HEADER FILES Comment [L11]: HEADER FILES

Conio.h
It is a library file which is included in the program this is used to use
Clrscr ( )
getch ( )
getchar ( ) etc.
We do not need to include this file in C program. It is necessary for C++ programs.
Conio stands for CONsole Input Output header file.

Math .h
This file is used for mathematical functions. These functions are like excel functions:-
Eg. pow( ), sqrt ( ), sin ( ), tan ( ) etc.

Introduction to C Language Comment [L12]: Introduction to C Language

The C Language is one of the most powerful language. In the beginning


due to the different architectures available, the programmer had to learn
different languages to create different types of applications. To overcome
this problem in 1972, Dennis Ritche at theAT & T Bell Laboratories,
USA developed C Language.
It is a combination of BCPL and B Language. The problem with Low
Level Languages is that they are very difficult for the humans to
understand and developed. On the other hand, High Level Languages
are easy for the humans to understand but slow in speed.
The C Language is high speed and easy to understand, so it is also term
as Middle Level Language.

JUMPS STATEMENTS Comment [L13]: JUMPS STATEMENTS

These are also called as branching statements. These statements transfer control to
another part of the program. When we want to break any loop condition or to
continue
any loop with skipping any values then we use these statements. There are three
types of jumps statements.
1. Continue
2. Break
3. Goto

Continue

This statement is used within the body of the loop. The continue statement moves
control in the beginning of the loop means to say that is used to skip any particular
output.
Example:
WAP to print series from 1 to 10 and skip only 5 and 7.
#include
void main ( )
{
int a;
clrscr ( );
for (a=1; a<=10; a++)
{
if (a= =5 | | a= = 7)
continue;
printf (“%d \n”,a);
}
getch ( );
}

Break
This statement is used to terminate any sequence or sequence of statement in switch
statement. This statement enforce indicate termination. In a loop when a break
statement is in computer the loop is terminated and a cursor moves to the next
statement or block;
Example:
WAP to print series from 1 to 10 and break on 5
#include
void main ( )
{
int a;
clrscr ( );
for (a=1; a<=10; a++)
{
if (a= =5)
break;
printf (“%d \n”,a);
}
getch ( );
}

Goto statement
It is used to alter or modify the normal sequence of program execution by transferring
the control to some other parts of the program. the control may be move or
transferred to any part of the program when we use goto statement we have to use a
label.
WAP TO FIND IF NUMBER=10 THEN GOOD ELSE BAD
#include
void main ()
{
int a;
clrscr ();
printf ("Enter any Number: ");
scanf ("%d",&a);
if (a= =10)
goto g;
else
goto b;
g:
printf ("Good");
goto end;
b:
printf ("Bad");
goto end;
end:
getch ();
}
WAP TO PRINT SERIES FROM 1 TO 10
#include
void main ()
{
int a;
clrscr ();
a=1;
check:
if (a< =10)
goto inc;
else
goto end;
inc:
printf (“%d \n”,a);
goto check;
end:
getch ( );
}

LOOPING Comment [L14]: LOOPING

These statements are used to control the flow of the program and repeat any process
multiple times according to user’s requirement. We can have three types of looping
control statements.
1. While
2. Do-while
3. For

While
It is an entry control loop statement, because it checks the condition first and then if
the condition is true the statements given in while loop will be executed.
SYNTAX:-
Initialization;
while (condition)
{
Statements;
Incremental / decrement;
}

Do-while
Do-while loop is also called exit control loop. It is different from while loop because
in
this loop the portion of the loop is executed minimum once and then at the end of the
loop the condition is being checked and if the value of any given condition is true or
false the structure of the loop is executed and the condition is checked after the
completion of true body part of the loop.
SYNTAX:-
Initialization
do
{
Statement;
Increment / decrement;
While
}

while (condition)
For loop
It is another looping statement or construct used to repeat any process according to
user requirement but it is different from while and do-while loop because in this loop
all the three steps of constructions of a loop are contained in single statement. It is
also an entry control loop. We can have three syntaxes to create for loop:-
for (initialization;
Test condition; Increment / decrement)
{
Statement;
}
for (; test condition; increment / decrement)
{
Statement;
}
for (; test condition;)
{
Statement;
Increment / decrement
}
#include
void main ( )
int a;
clrscr ( );
for (a=1; a<=10; a++)
{
printf (“%d \n”,a);
}
getch ( );
}

MACRO
Macro is a substitution of a string that is placed in a program. It is placed by the
definition when program is compiled and we have to use (#) symbol in front of this.
We can have different macros like:-
#define, #if, #else.
It is different from preprocessor directive, because pre processor directive is used to
link files with the object code and macro is used to define any string and we always or
maximum use #define macro.
#include <stdio.h>
#define wait getch ( )
# define flot float
void main ( )
…….
…….
flot f,c;
…….
…….
…….
…….
wait;
}

NESTED IF Comment [L15]: NESTED IF

If within if is called nested if and it is used when we have multiple conditions to check
and when any if condition contains another if statement then that is called ‘nested
if’.
If the external condition is true, then the internal if condition or condition are
executed and if the condition is false then the else portion is executed of the external
if statement
SYTAX
if (condition)
{
…….
…….
}
if (condition)
{
…….
…….
}
else if (condition)
{
…….
…….
}
else if (condition)
{
…….
…….
}
else
{
…….
……. }
}
else
{
…….
…….
}

NESTED LOOP Comment [L16]: NESTED LOOP

These loops are the loops which contain another looping statement in a single loop.
These types of loops are used to create matrix. Any loop can contain a number of loop
statements in itself. If we are using loop within loop that is called nested loop. In this
the outer loop is used for counting rows and the internal loop is used for counting
columns
SYNTAX:-
for (initializing ; test condition ; increment / decrement)
{
statement;
for (initializing ; test condition ; increment / decrement)
{
body of inner loop;
}
statement;
}
PROGRAM
#include
void main ( )
{
int i, j;
clrscr ( );
for (j=1; j<=4; j++)
{
for (i=1; i<=5; i++)
{
printf (“*”)
}
printf (“\n”);
}
getch ( );
}
OUTPUT OF THIS PROGRAM IS
****
****
****
****

OPERATORS Comment [L17]: OPERATORS

Every language contains variable and data types and also support the concept of
operators. C language has over forty operators, but hardly all they are used. These
are
divided onto nine categories:-
(1) Arithmetic
(2) Assignment
(3) Logical
(4) Relational
(5) Modulas
(6) Increment / Decrement
(7) Conditional
(8) Bit wise
(9) Special

Arithmetic Operators (+ - * /)
These are the common operators used to perform any arithmetic calculations. These
are basically used on minimum two variables or constants. These operators contain +,
-, *, /.

Assignment Operators
These operators are used to assign any value to the variable or constant. The main
assignment operator is ‘=’.

We have some short assignment operators. Suppose a=10

Logical operators
These are used to test more than one condition or we can say conditional expression,
so that you can make a decision on the basis of that condition. These operators are

Relational operators
These operators are also called comparison operators. You can use relational
operators, whenever you want to compare two quantities and variables or constants
and you want to take decision on the basis of that condition. Then these operators are
used.
We have following types of operators:-
>
<
>=
<=
==
!=

Modulas Operator
This operator is used to find out the reminder of any value.
R=25%10 R=5

Increment / Decrement operators


These operators are also called unary operators. These operators are used when we
want to perform any action on single operand. These operators are used when we
want
to increase or decrease value of any variable by one.
Increment operator is ++
Decrement operator is –

We have two types of unary operators

Post fix
This operator is used to assign any value of variable to another variable according to
use requirement. In this operator firstly the value of a variable is copied to another
variable and then the value is increased or decreased.
a=10
a++ a=11

Pre-fix
This operator is used to assign value to any variable according to user requirement, so
that the same value is copied to another variable. Firstly the value of variable is
increased or decreased and then it is copied to any other variable.
a=10
++a a=11

Conditional operators
These operators are also called ternary operators. These are used to check any
condition or expression and can be used to compare two conditional expressions and
produce a result if the condition is true or false. Operators used for conditional
operators are “?” and “:”
Syntax:-
(expression / condition)? True statement (if) : false statement (else)
Bit wise operators
C is known as assembly language because it provides us bit wise operators, which are
normally associated with assembly language programming. C language has a powerful
set of special operators which are capable of manipulating data at bit level. These are
as follows:-

1) & - Bit wise (and)


2) ! - Bit wise (or)
3) ^ - Bit wise (exponent)
4) << - Shift left
5) >> - Shift right

Special operators
Special operators are provided by C. these operators are as follows:-
1. commas operators (,)
2. pointer operators (*, &)
3. sizeof ( )

Relational operators
These operators are also called comparison operators. You can use relational
operators, whenever you want to compare two quantities and variables or constants
and you want to take decision on the basis of that condition. Then these operators are
used.
We have following types of operators:-
>
<
>=
<=
==
!=

Modulas Operator
This operator is used to find out the reminder of any value.
R=25%10 R=5
Increment / Decrement operators
These operators are also called unary operators. These operators are used when we
want to perform any action on single operand. These operators are used when we
want
to increase or decrease value of any variable by one.
Increment operator is ++
Decrement operator is –

We have two types of unary operators


Post fix
This operator is used to assign any value of variable to another variable according to
use requirement. In this operator firstly the value of a variable is copied to another
variable and then the value is increased or decreased.
a=10
a++ a=11

Pre-fix
This operator is used to assign value to any variable according to user requirement, so
that the same value is copied to another variable. Firstly the value of variable is
increased or decreased and then it is copied to any other variable.
a=10
++a a=11

Conditional operators
These operators are also called ternary operators. These are used to check any
condition or expression and can be used to compare two conditional expressions and
produce a result if the condition is true or false. Operators used for conditional
operators are “?” and “:”
Syntax:-
(expression / condition)? True statement (if) : false statement (else)

Bit wise operators


C is known as assembly language because it provides us bit wise operators, which are
normally associated with assembly language programming. C language has a powerful
set of special operators which are capable of manipulating data at bit level. These are
as follows:-
1) & - Bit wise (and)
2) ! - Bit wise (or)
3) ^ - Bit wise (exponent)
4) << - Shift left
5) >> - Shift right

Special operators
Special operators are provided by C. these operators are as follows:-

1. commas operators (,)


2. pointer operators (*, &)
3. sizeof ( )

PSEUDO CODE Comment [L18]: PSEUDO CODE

These are basically the instructions written in plain English to solve any problem. It
makes a layman understand the complexity of the problem. Pseudo is a way of
describing and algorithm without using any specific programming language. It can be
the example of real life examples, but it cannot be implemented in computer. It is
written roughly at same level of detail.

Conventions (Rules) for creating Variable


1. First Character of variable should be an alphabet
2. The name of variables can be in lower case as well as upper case.
3. Two or more variables cannot have same name.
4. It Cannot contain any space in between variable name.
5. It cannot contain Period Sign ( . )
6. We cannot use keywords as variable names i.e. variable name like int, float, if are
invalid.
7. No special symbol is allowed in variable name.
8. A variable name should not be more than 40 characters, but it is safer to declare
variable name as short as possible
Example
int a,b,c;
OR
int a=10, b=20, c;

STRING Comment [L19]:


STRING
String are the combination of number of characters these are used to
store any word
in any variable of constant. A string is an array of character. It is
internally
represented in system by using ASCII value. Every single character can
have its own
ASCII value in the system. A character string is stored in one array of
character type.

e.g. “Ram” contains ASCII value per location, when we are using strings
and then
these strings are always terminated by character ‘\0’. We use conversion
specifier %s
to set any string we can have any string as follows:-

char nm [25]

When we store any value in nm variable then it can hold only 24


character because at
the end of the string one character is consumed automatically by ‘\0’.

1. strlen - string length

2. strcpy - string copy

3. strcmp - string compare

4. strups - string upper

5. strlwr - string lower

6. strcat - string concatenate

7. strstr - string string


SWITCH CASE / SELECT CASE Comment [L20]:
SWITCH CASE / SELECT CASE
These statements are used with the replacement of if-else and these statements are
used when we have multiple options or choices. These choices can be limited and
when we use switch case we can use only integer or character variable as expression.
#include <stdio.h>
void main()
{
int,ch qty;
long tb,dis,nb;
clrscr();
printf("1.BPL\n2.Onida\n3.Sony\n4.Samsung\n5.LG\n");
printf("\nEnter Your Choice: ");
fflush(stdin);
scanf("%d",&ch);
printf("Enter Qty: ");
scanf("%d",&qty);
switch(ch)
{
case 1:tb=(long)qty*10000;
printf("\nBPL is %ld",tb);
break;
case 2:tb=(long)qty*12000;
printf("\nOnida is %ld",tb);
break;
case 3:tb=(long)qty*11500;

printf("\nSony is %ld ",tb);


break;
case 4:tb=(long)qty*11000;
printf("\nSamsung is %ld ",tb);
break;
case 5:tb=(long)qty*13000;
printf("\nLG is %ld ",tb);
break;
default:
printf("Wrong Choice...");
}
dis=(tb*10)/100;
nb=tb-dis;
printf("\nDiscount is %ld",dis);
printf("\nNet bill is %ld",nb);
getch();
}
TYPE CASTING Comment [L21]: TYPE CASTING

It is used to convert on data at a time. It is required to used different type of


constants and variables in expression then we have convert that expression into
another data type, but certain rules are used during conversion of data type the
computer consider one operand at a time involving two operands. We can have two
types of type casting.
1. Implicit
2. Explicit

Implicit

When we are converting any data type which contains shorter values then along data
type that conversion is called implicit or in simple language we can say when user do
not need to convert any data type into another data type and it is automatically done
through computer system that is called implicit type conversion. The conversion is not
transparent to the user or the programmer and is done by the compiler. This converts
narrow type to wider type so that use can avoid the information to the system.
#include
void main ()
{
float c,f;
clrscr ();
printf ("Enter the value of celcius: ");
scanf ("%f",&c);
f=9.0/5.0*c+32;
printf ("\Fehranite is %.2f",f);
getch ();
}

Explicit

Explicit type casting is done by the programmer manually. When the programmer
wants a result of an expression to be in particular type, then we use explicit type

casting. This type casting is done by casting operators ‘( )’ and data type.

#include
void main ()
{
float c,f;
clrscr ();
printf ("Enter the value of celcius: ");
scanf ("%f",&c);
f=(float) 9/5*c+32;
printf ("\Fehranite is %.2f",f);
getch ();
}

VARIABLES Comment [L22]: VARIABLES


It is the name given to stored reason of the memory and it provides us the facility to
change the value of it during the execution. Variable names are the name given to the
location in memory of a computer where different values are stored. The location
which contains these constants can be an integer, character, real numbers.

Das könnte Ihnen auch gefallen