Working process of printf()
1) In printf() a format specifier associate with outside value left to left.
Example:- int a =10, b=5;
printf(“a=%d,b=%d",a,b);
Output----- a=10,b=5
2) In printf(), a work will be perform right to left.
Example:- int a;
printf(“a=%d”,a,++a,a=20);
Output----- a=21
3) When outside value received into first double quotes of printf() then printf() display it on monitor.
example:- int a=20;
printf(“a=10”,a,++a,a=20);
Output----- a=21
4) Lastly printf() returns total number of character enclosed within it’s first double quotes.
Example:- int r;
r=printf(“Wel %s”,”come”);
printf(“\n r= %d”,r);
Output------ Welcome
r= 7
Working process of scanf()
(i) In scanf() a format specifier associate with variable left to left.
Example:- scanf(“%d %d”,&a,&b);
(ii) Lastly scanf() returns total number of value accepted from keyboard.
Exampl\e:- printf(“enter two number”);
r=scanf(“%d %d”,&a,&b);
printf(“r=%d”,r);
Output------à enter two number 5
10
r=2
Explanation:-
1) write a program in C to accept one integer and one fractional number from keyboard and display its product.
void main()
{
int a;
float b;
clrscr();
printf(“Enter two number:”);
scanf(“%d @ %f”,&a,&b);
printf(“a*b = %f”,a*b);
getch();
}
Output-----à Enter two number:5 @ 2.5
a*b=12.5
2) void main()
{
int a,b,r;
clrscr();
r=printf(“\n%d,%d”,scanf(“%d%d”,&a,7b),printf(“enter two number:”));
printf(“\n r=%d”,r);
getch();
}
Output----à enter two number: 5
10
2,13
r=5
Comments
Post a Comment