Description
Cookie multiplication
Jane has two types of cookies (of number N and M, respectively), and she uses a magic spell to produce more cookies (N * M in total).
However, there are many cookies. Jane asks you to help her calculate the number of new cookies she can make.
Input
3 integers K, N, M in order.
N , M means the number of cookies.
If the digits of new cookies is smaller than K,
please left pad with zeros up to K digits.
Data range:
0 <= N, M <= 2^32-1
1 <= K <= 1000000
Output
Output a single line with the number N * M, and a '\n' at the end.
Hint: overflow , printf skill
The * Modifier with printf() and scanf()
printf()
Suppose that you don't want to commit yourself to a field width in advance but rather you want
the program to specify it. You can do this by using * instead of a number for the field width, but
you also have to use an argument to tell what the field width should be. That is, if you have the
conversion specifier %*d, the argument list should include a value for * and a value for d. The
technique also can be used with floating-point values to specify the precision as well as the field
width.
// uses variable-width output field
#include <stdio.h>
int main(void)
{
unsigned width, precision;
int number = 256;
double weight = 242.5;
printf("What field width?\n");
scanf("%d", &width);
printf("The number is :%*d:\n", width, number);
printf("Now enter a width and a precision:\n");
scanf("%d %d", &width, &precision);
printf("Weight = %*.*f\n", width, precision, weight);
printf("Done!\n");
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------
Sample run
What field width?
6
The number is : 256:
Now enter a width and a precision:
8 3
Weight = 242.500
Done!
scanf()
The * serves quite a different purpose for scanf(). When placed between the % and the specifier
letter, it causes that function to skip over corresponding input.
This skipping facility is useful if, for example, a program needs to read a particular column of a
file that has data arranged in uniform columns.
// skips over first two integers of input
#include <stdio.h>
int main(void)
{
int n;
printf("Please enter three integers:\n");
scanf("%*d %*d %d", &n);
printf("The last integer was %d\n", n);
return 0;
}
-------------------------------------------------------------------------------------------------------------------------------
Sample run
Please enter three integers:
2004 2005 2006
The last integer was 2006
If you don't know how to search more information, you can look at this reference.
It really helps.
http://www.cplusplus.com/reference/cstdio/printf
Tags