This program can be used to add two positive integers without using any operator.
<= How this code works, lets understand =>
- in this code we are passing %*c inside printf function
- star will be replaced by the value of variable a and variable b
- c will print spaces- so printf will be evaluated like printf("%10c%20c",' ',' ');
- which means the printf will show 10 spaces then 30 spaces, so total 30 spaces will be printed
- then printf will return the no of characters those are printed, the returned value will be stored inside variable result
- star will be replaced by the value of variable a and variable b
- c will print spaces- so printf will be evaluated like printf("%10c%20c",' ',' ');
- which means the printf will show 10 spaces then 30 spaces, so total 30 spaces will be printed
- then printf will return the no of characters those are printed, the returned value will be stored inside variable result
#include<stdio.h>
{
int a = 10;
int b = 20;
int result;
result = printf("%*c%*c",a,' ',b,' ');
printf("\raddition of %d and %d is %d",a,b,result);
}
What is c here
ReplyDeleteWhat is c here
ReplyDelete"c" is a format specifier for char
Deletei tried this code as.. a,' ',b,' in 7th line..but its not working
ReplyDeletehelp me out with correct code syntax!!
Dear Prerna, the code is absolute correct. But, It will work for postive values only. If possible please post your code as comment. I will help for sure.
Delete