History:
C language was developed at AT & T's Bell laboratories of USA in 1972. It is designed and written by Dennis Ritchie.
Features of C language:
1.Middle level language
2.Structural
3.Easy to understand
4.Portability i.e., programs written in one system can be copied into another system and can be executed easily
4.More efficient
5.Compile language
6.Windows, Linux and Unix are written in C because of its high performance
Compiler: basically the system understands only machine level language i.e., written in 1's and 0's.
Here compiler does the job of converting the source code to machine level language
Constant:
1. A constant is an entity that doesn't change
2.Alphabets, numbers and special symbols can be used to form constants.
constants - Integer constants - 5, 12, 28, 264, 768 etc
Real constants - 5.20, 6.25, 235.12, 5.21 etc
Character constants- 'a', 'h', '9', '=' etc
Variable:
A variable is an entity that does change.
Ex: #include<stdio.h>
#include<conio.h>
int main()
{
int x=10;
printf("the value of x is %d\n",x);
x=x+1;
printf("the value of x is %d\n",x);
getch();
return 0;
}
output: the value of x is 10
the value of x is 20
Here x is a variable and 10, 20 are integer constants.
Variable types:
1. Integer - keyword is int ex: int a, int x
2.Real or floating point type - keyword is float ex: float area, float average, etc
3.Character - keyword is char ex: char a, char i, etc
Keywords:
These are the words whose meaning has already been explained to the c compiler.
By using keywords we can construct the meaningfull statements.
Ex: break, int, float, char, if, for.....etc
Note: keywords cannot be used as variable names.
Basic programs:
// to print hello
#include<stdio.h>
#include<conio.h>
int main()
{
printf("hello");
getch();
return 0;
}
Description:
# - Pre processor directive: it is a program that processes our source code before it is passed to the compiler
In the C Programming Language, the Standard Library Functions are divided into several header files.
The following is a list of functions found within the <stdio.h> header file:
main()
{
/*main() is a function . A function is nothing but a set of statements.In a C program there can be multiple functions.All statements that belong to main() are enclosed within a pair of braces {} as shown here.*/
}
printf(" enter x value"); : standard function used to print something on to the screen.
scanf("%d",&x); :reads values or data from the user through input devices.
getch(); :It reads character from keyboard.
void main() : does not expect any output value at the end of the program
int main() :expects some integer value at the end of the program
//program to calculate simple interest
#include<stdio.h>
#include<conio.h>
int main()
{
int p,n;
float r,si;
p=1000;
n=3;
r=8.5;
//formula for simple interest
si=(p*n*r)/100;
printf("%f\n",si);
return 0;
}
output: 255.000000
//To calculate simple interest for any values of p, n and r
#include<stdio.h>
#include<conio.h>
int main()
{
int p,n;
float r,si;
printf("enter values of p, n,r");
scanf("%d %d %f",&p,&n,&r);
si=(p*n*r)/100;
printf("%f",si);
return 0;
}
output: enter values of p, n,r 4 5 2
0.400000
C language was developed at AT & T's Bell laboratories of USA in 1972. It is designed and written by Dennis Ritchie.
Features of C language:
1.Middle level language
2.Structural
3.Easy to understand
4.Portability i.e., programs written in one system can be copied into another system and can be executed easily
4.More efficient
5.Compile language
6.Windows, Linux and Unix are written in C because of its high performance
Compiler: basically the system understands only machine level language i.e., written in 1's and 0's.
Here compiler does the job of converting the source code to machine level language
Constant:
1. A constant is an entity that doesn't change
2.Alphabets, numbers and special symbols can be used to form constants.
constants - Integer constants - 5, 12, 28, 264, 768 etc
Real constants - 5.20, 6.25, 235.12, 5.21 etc
Character constants- 'a', 'h', '9', '=' etc
Variable:
A variable is an entity that does change.
Ex: #include<stdio.h>
#include<conio.h>
int main()
{
int x=10;
printf("the value of x is %d\n",x);
x=x+1;
printf("the value of x is %d\n",x);
getch();
return 0;
}
output: the value of x is 10
the value of x is 20
Here x is a variable and 10, 20 are integer constants.
Variable types:
1. Integer - keyword is int ex: int a, int x
2.Real or floating point type - keyword is float ex: float area, float average, etc
3.Character - keyword is char ex: char a, char i, etc
Keywords:
These are the words whose meaning has already been explained to the c compiler.
By using keywords we can construct the meaningfull statements.
Ex: break, int, float, char, if, for.....etc
Note: keywords cannot be used as variable names.
Basic programs:
// to print hello
#include<stdio.h>
#include<conio.h>
int main()
{
printf("hello");
getch();
return 0;
}
Description:
# - Pre processor directive: it is a program that processes our source code before it is passed to the compiler
In the C Programming Language, the Standard Library Functions are divided into several header files.
The following is a list of functions found within the <stdio.h> header file:
FORMATTED INPUT/OUTPUT FUNCTIONS
fprintf Formatted File Write
fscanf Formatted File Read
printf Formatted Write
scanf Formatted read
sprintf Formatted string write
sscanf Formatted string read
vfprintf Formatted File Write Using Variable Argument List
vprintf Formatted Write Using Variable Argument List
vsprintf Formatted String Write Using Variable Argument List
fscanf Formatted File Read
printf Formatted Write
scanf Formatted read
sprintf Formatted string write
sscanf Formatted string read
vfprintf Formatted File Write Using Variable Argument List
vprintf Formatted Write Using Variable Argument List
vsprintf Formatted String Write Using Variable Argument List
CLOSE FILE
FLUSH FILE BUFFER
OPEN FILE
REOPEN FILE
REMOVE FILE
RENAME FILE
SET BUFFER (OBSOLETE)
SET BUFFER
CREATE TEMPORARY FILE
GENERATE TEMPORARY FILE NAME
CLOSE FILE
FLUSH FILE BUFFER
OPEN FILE
REOPEN FILE
REMOVE FILE
RENAME FILE
SET BUFFER (OBSOLETE)
SET BUFFER
CREATE TEMPORARY FILE
GENERATE TEMPORARY FILE NAME
CHARACTER INPUT/OUTPUT FUNCTIONS
Read Character from File
|
|
Read String from File
|
|
Write Character to File
|
|
Write String to File
|
|
Read Characters from File
|
|
Read Character
|
|
Read String
|
|
Write Character to File
|
|
Write Character
|
|
Write String
|
|
Unread Character
|
BLOCK INPUT/OUTPUT FUNCTIONS
conio.h library functions
All C inbuilt functions which are declared in conio.h header file are given below.
List of inbuilt C functions in conio.h file:
S.no | Function | Description |
1 | clrscr() | This function is used to clear the output screen. |
2 | getch() | It reads character from keyboard |
3 | getche() | It reads character from keyboard and echoes to o/p screen |
4 | textcolor() | This function is used to change the text color |
5 | textbackground() | This function is used to change text background |
main()
{
/*main() is a function . A function is nothing but a set of statements.In a C program there can be multiple functions.All statements that belong to main() are enclosed within a pair of braces {} as shown here.*/
}
printf(" enter x value"); : standard function used to print something on to the screen.
scanf("%d",&x); :reads values or data from the user through input devices.
getch(); :It reads character from keyboard.
void main() : does not expect any output value at the end of the program
int main() :expects some integer value at the end of the program
//program to calculate simple interest
#include<stdio.h>
#include<conio.h>
int main()
{
int p,n;
float r,si;
p=1000;
n=3;
r=8.5;
//formula for simple interest
si=(p*n*r)/100;
printf("%f\n",si);
return 0;
}
output: 255.000000
//To calculate simple interest for any values of p, n and r
#include<stdio.h>
#include<conio.h>
int main()
{
int p,n;
float r,si;
printf("enter values of p, n,r");
scanf("%d %d %f",&p,&n,&r);
si=(p*n*r)/100;
printf("%f",si);
return 0;
}
output: enter values of p, n,r 4 5 2
0.400000
No comments:
Post a Comment