Use of Printf and Scanf
Use of ''printf" and ''scanf" function with all formating facilities :
In c programming language, "printf" and "scanf" are inbuilt library function.
These functions are declared and defined in the header file ' ' stdio.h".
Printf
It is used to print the output on to the screen
We cab use printf() function with different format specifier,Following are some of them:-
(1) %d is used to display the valu of an integer variable.
(2) %c is used to display chracter.
(3) %f is used for float variable.
(4) %s for string variable.
(5) %if for double.
(6) %x for hexadecimal variable.
(7) \n to generate a newline.
scanf :-
It is used to read different type of input from keyboard.
we can use scanf () function with different format specifier.
Following we some of them:-
(1) %d - the value entered is received as an integer.
(2) %s - the value entered is received as an string.
program to print sum of two numbers
Let's see a simple example:-
- #include<stdio.h>
- #include<conio.h>
- int main()
- {
- int x=0,y=0,result=0;
- printf("enter first number:");
- scanf("%d",&x);
- printf("enter second number:");
- scanf("%d",&y);
- result=x+y;
- printf("sum of two numbers:%d ",result);
- getch();
- }
No comments:
Post a Comment