In Static time the value of the Variable are does not changed.So if we want to changed the value of Variable alternatively we can use function scanf().
Scanf():-
It is standard input function which is used to read different type of values from standard input device.
Syntax 1 :-
scanf("Control String",&Variable name);
Ex :-
scanf("%d",&a);
Syntax 2:-
scanf("Control String",&var name 1,-------var name n);
Ex :-
scanf("%d%d",&a,------&n);
#include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("enter the a value:"); scanf("%d",&a); printf("enter the b value:"); scanf("%d",&b); printf("\n"); printf("the value of a is :%d\n",a); printf("the value of b is :%d",b); getch(); } |
Output:-
enter the a value:5 enter the b value:8 the value of a is:5 the value of b is:8 |
* write a program to print two float values on standard output device.
#include<stdio.h> #include<conio.h> void main() { float a,b; clrscr(); printf("enter the a value is:"); scanf("%f",&a); printf("enter the b value is:"); scanf("%f",&b); printf("\n\n"); printf("the value of a is:%f\n",a); printf("the value of b is:%f",b); getch(); } |
Output:-
enter the a value:5 enter the b value:8.45 the value of a is:5.000000 the value of b is:8.450000 |
* write a program to print all datatype values.
1st Model
#include<stdio.h> #include<conio.h> void main() { int i; char c; float f; clrscr(); printf(“enter integer value:”); scanf(“%i”,&i); printf(“enter character value:”); scanf(“%c”,&c); printf(“enter float value:”); scanf(“%f”,&f); printf(“\n\n”); printf(“integer value =%d\n”,i); printf(“character value =%c\n”,c); printf(“real number=%f\n”,f); getch(); } |
another Model
#include<stdio.h> #include<conio.h> void main() { int i,char c,float f; clrscr(); printf(“enter any integer,character,float values:\n”); scanf(“%d,%c,%f”,&i,&c,&f); printf(“\n\n”); printf(“integer value =%d\n”,i); printf(“character value =%c\n”,c); printf(“real number=%f\n”,f); getch(); } |
Output:-
enter integer value:4 enter character value:c enter float value:6.54 integer value=4 character value=c real number=6.540000 |
__________________________________________________________________________________
__________________________________________________________________________________
Post a Comment