2. Index
2
Page----4
1. Introduction of c
Page----9
2. Datatype, constant
and variable
Page----14
3. Operator
Page----18
4. Control structure
Page----26
5. Looping
Page----39
8. String
Page----35
7. Array
Page----31
6. Looping with
pattern
Page----44
9. User defined
function
3. 1.Introduction of c
A. History and importance of c
B. Difference between compiler and interpreter
C. Simple printf() function
D. Escape sequence character
3
4. A. History and importance of c
C is popular high level programming language. It was developed by Dennis Ritchie at
AT&T Bell Laboratories in 1972. It was derived from earlier programming language
called B. It was originally designed to write system programs under UNIX operating
system.
4
5. B. Difference between compiler and
interpreter
5
Compiler Interpreter
C, C++, Go, Fortran Python, PHP, Ruby
Language Language
Machine code Ready to run!
Ready to run! Virtual Machine
Machine code
6. C. Simple printf() function
6
printf() is pre-defined function from the header stdio.h
printf() is used to write formatted output to console
Example -
printf(“hello!!”); output : hello!!
printf(“My age is %d”,23); output : my age is 23
where %d is format specifier for integer.
7. D. Escape sequence character
It is composed of two or more character starting with backslash.
Escape means skip.
Sequence character means always together.
Example -
printf(“”); output -
printf(“n”); output - n
printf(“%%”); output - %
printf(“%%d”); output - %d
7
8. 2. Data type, constant & variable
A. Datatype
B. Constant variable
C. Variable
8
9. A. Data type in c
9
Pre-defined
i.Int
ii. Float
iii. Char
iv. Void
Derived
i. Array
ii. Pointer
User-defined
i.Structure
ii. Union
iii. Enum
1 2 3
10. B. Constant
Definition –
This is a variable which is only
initialized once and it’s value cannot be
modifiable.
Note –
A constant variable name should
be in capitalized latter.
How to create a constant variable -
1] Using a const variable.
2] By defining a marco.
3] Initialization must be done
while declaring a constant
variable.
10
Example –
1] const float PI = 3.14;
printf(“%f”,PI);
2] #define Min 1
# define Max 9
main()
{
printf(“%d%d”,Min,Max);
}
12. C. Variable
Definition –
It is a container which is used to store some data.
Rules – A variable name
1] must be started with alphabet or underscore(_).
2] cannot be starts with numeric digit or any special symbol.
3] cannot contain any whitespace.
4] cannot be same as any keyword.
12
13. 3. Operator & expression
A. Types of operator
B. Operator precedence
C. Type Conversation
13
15. B. Operator precedence
15
No. Priority Order
1 ( ) Left to right
2 % / * Left to right
3 + - Left to right
4 = Right to left
Definition :
In a given expression which operator runs first and in which order.
16. C. Type conversation(Type casting)
16
Definition :
Convert one data type into another data type for temporary time.
Example :
float a;
a = 5.9;
printf(“%d”, (int)a);
17. 4. Control structure
A. If statement
B. If else
C. Ladder
D. Nested if
E. Ternary operator
F. Switch case
17
18. 18
18
Control structure
If
if(condition)
{
//true
}
If else Switch case
If-else If-else if Nested if
if (condition)
{
//true
}
else
{
//false
}
if(condition 1)
{
// true
}
else if(condition
2)
{
//true
}
else
{
}
if (condition 1)
{
if (condition)
{
}
else
{
}
}
else
{
if (condition)
{
}
else
{
}
}
switch (variable)
{
case 1:
break;
Case 2:
break;
default:
}
condition
?
// true
:
//false;
Ternary operate
19. A. If statement
19
Variable x is
less than y
Example : Find which value is less?
Output
#include<stdio.h>
Int main()
{
int x = 20;
int y = 22;
if (x<y)
{
printf(“Variable x is less than y”);
}
}
20. B. If else
20
The value is
greater than
10
Output
#include<stdio.h>
int main()
{ int num=19;
if (num<10)
{ printf("The value is less than 10"); }
else
{ printf("The value is greater than 10"); }
}
Example : The value is less than ten or greater than ten?
21. C. Ladder(steps)
21
First class
Example : Prints the grade as per the marks scored in a test.
Output
#include<stdio.h>
main()
{ int marks=83;
If(marks>75)
{ printf("First class"); }
else if(marks>65)
{ printf("Second class"); }
else if(marks>55)
{ printf("Third class"); }
else
{ printf("Fourth class"); }
}
22. D. Nested if
22
The value is
greater than
10
Output
Example : Checks if a number is less or greater than 10
#include<stdio.h>
main()
{ int num=100;
If(num<10)
{
if(num==1)
{ printf("The value is:%dn",num); }
else
{ printf("The value is greater than 1"); }
}
else
{ printf("The value is greater than 10"); }
}
23. E. Ternary operator
23
C is max
Example : find maximum number from 3 number.
Output
#include<stdio.h>
int main()
{
int a=10,b=100,c=200;
(a==b && b==c) ?
Printf(“all numbers are same”):
a>b ?
a>c ? printf(“a is max”)
: printf(“a is max”)
: b>c ? printf(“b is max”)
: printf(“c is max”);
}
24. F. Switch case (Menu driven)
24
The value is 8
Output
Example : Check what number is ?
#include <stdio.h>
main()
{
int num = 8;
switch (num)
{
case 7: printf("Value is 7");
break;
case 8: printf("Value is 8");
break;
case 9: printf("Value is 9");
break;
default: printf("Out of range");
}
}
39. A. String concept
The string can be defined as the one-dimensional array of characters
terminated by a null ('0'). The character array or the string is used to
manipulate text such as word or sentences.
39
40. B. gets() and puts()
40
gets() Puts()
The gets() function is similar to scanf()
function but it allows entering some
characters by the user in string
Syntax :
char[ ]
gets( char [ ])
The puts() function is similar
to printf() function. but puts() function
is used to display only the string after
reading by gets() function entered by
user(gets similar to scanf() function)
Syntax :
puts(char[ ])
41. C. String function
strlwr() :
char a[100];
puts(“enter aby string:”);
gets(a); // WELCOME
printf(“%s”,strlwr(a)); // welcome
strupr() :
char a[100];
puts(“enter aby string:”);
gets(a); // welcome
printf(“%s”,strupr(a)); // WELCOME
strrev() :
char a[100];
puts(“enter aby string:”);
gets(a); // priya
printf(“%s”,strrev(a)); // ayirp
strlen() :
char a[100];
puts(“enter aby string:”);
gets(a); // WELCOME
printf(“%s”,strlen(a)); // 7
strcpy() :
char a[100];
strcpy(a,”home”);
puts(a); // home
43. A. Concept of UDF
43
Library function
i. printf()
ii. scanf()
iii. gets()
iv. puts()
User defined function
i. Take nothing, return nothing
ii. Take something, return nothing
iii. Take nothing, return something
iv. Take something, return something
1 2
Definition –
A block of code that is reusable its called function.
There is two type of function :-
44. B. Recursion
44
24
Output
Example : Find factorial of number?
#include <stdio.h>
Int fact(int n)
{ if(n==1)
{ return 1;}
else
{ return n * fact(n-1) ;}
Void main()
{
printf(“%d ”,fact(4));
}
Definition –
A function call it’s self that means recursion.