INTRODUCTION OF MAIN FUNCTION & HEADER FILES IN C
Ø HEADER FILES :-
Header file is a File with some extension (i.e. ‘.h’) Which contains Input and output and it also contains C function Declarations and some definitions that can be shared between several source files. Header files are comes with compiler so header files are pre-define with compiler.
Following are some Header files that are used during programs.
1)
#include<stdio.h>
2)
#include<conio.h>
3)
#include<stdlib.h>
4)
#include<math.h>
5) #include<string.h>
#include<stdio.h>
<stdio.h> which stands for standard input and output used to take input with the help of scanf() function and display that output with the help of printf() function.
printf() FUNCTION –
PRINTF function are inbuilt library function in c programming language which are available in c library. PRINTF() function are used to print integer value(%d), characters(%c), float values(%f), character string(%s). than PRINTF() function are used to print this type of values onto the output screen.
EX-
FOR INTEGER VALUE – printf(“%d”, a); [proper syntax]
If user enters any integer value and user wants to print that value than above syntax are used to print the integer numbers. Here “%d” for integer value. ‘a’ means the value taken by ‘a’ using scanf function is print onto output screen. If we want to print ‘b’ so enter the value in ‘b’ using scanf function and print that value so just replace b in place of a.
FOR FLOAT VALUE – printf(“%f”, a);
If user enters any float value and user wants to print that value than above syntax are used to print the integer numbers. Here “%f” for integer value. ‘a’ means the value taken by ‘a’ using scanf function is print onto output screen.
FOR CHARACTER VALUE – printf(“%c”, a);
If user enters any float value and user wants to print that value than above syntax are used to print the integer numbers. Here “%f” for integer value. ‘a’ means the value taken by ‘a’ using scanf function is print onto output screen.
FOR CHARACTER STRING VALUE – printf(“%s”, a);
If user enters any float value and user wants to print that value than above syntax are used to print the integer numbers. Here “%f” for integer value. ‘a’ means the value taken by ‘a’ using scanf function is print onto output screen.
The SCANF function is used to allow input from users in which the value is given by keyboard. Using SCANF function user can add different values at 1 time so it is quit useful during program. In simple program it is good enough and simple to use.
EX –
FOR INTEGER VALUE – scanf(“%d”, &a); [proper syntax]
If user enters any integer value than syntax of scanf function are shows as above example. This example shows us The program read an Integer value that value is enter by user with the help of keyboard. Here “%d” is for integer values. &a means user enter that integer value in a only.
FOR FLOAT VALUE – scanf(“%f”, &a);
If user enters any float value (i.e. 0.5) than the syntax of scanf function are shows as above example. This example shows us The program read an float value that value is enter by user with the help of keyboard. Here ‘%f’ is for integer values. &a means user enter the float value in a only as per above example.
FOR CHARACTER VALUE – scanf(“%c”, &a);
Here user enters character value (i.e. A, B, ….) than the syntax of scanf function is shows as above example. Here “%c” is for character values.
FOR CHARACTER STRING VALUE – scanf(“%s”, &a);
Here Character string means sentence of words (i.e. Our website name is ProgramCode1907………). Here “%s” is for character string.
· #include<conio.h>
<conio.h> this file contains the definitions of function used for reading and printing the data at the console as similar as <stdio.h>. This header file contains GETCH() function also.
getch() FUNCTION – getch();
GETCH() function is used to holds the output screen and wait until user press any key. Due to it we can able to see the output screen until user doesn’t press any key.
· #include<stdlib.h>
<stdlib.h> is stands for standard library of c programming language which include functions that involving memory allocation, process control, conversions and others.
· #include<math.h>
<math.h> header file defines various mathematical function and one marco. Function that are in math.h header file that double as an argument and return double as result.
· #include<string.h>
<string.h> is header file in c standard
library for the c programming language
which contains constants and declaration of function and types used not only
for string handling but also various memory handling functions.
Ø Clrscr() Function :-
CLRSCR() functions syntax
is - clrscr();
It is used to clear the
console screen of previous output. Due to that we can see clear output on
console screen.
Ø main() Function :-
main() function is very important part of hole program. It is the point at which execution of program is started. When a c program is executed, the execution control goes directly to the main() function. Every c program have c program.
SYNTEX OF MAIN() FUNCTION IS –
void
main()
{
Declaration part…. (here we can declare variables);
Clrscr(); (It is common part in every program)
……………;
……………;
……………; (this is our main logic code)
……………;
getch(); (it is also common part in every program)
}
EX –
Program of add two
numbers –
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
scanf(“%d”,&a);
scanf(“%d”,&b);
c=a+b;
printf(“addition is %d”,c);
getch();
}
0 Comments
If You have any query, Please let me know..