forked from taniadovzhenko/CppPracticum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.2.6.c
More file actions
51 lines (41 loc) · 755 Bytes
/
task1.2.6.c
File metadata and controls
51 lines (41 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
// for C89 compatibility
// instead of scanf("%hhu")
unsigned my_scanf_to_uchar(unsigned char *puchar);
int main(){
unsigned char n; // 0..255
printf("n=");
scanf("%hhu",&n);
//my_scanf_to_uchar(&n);
long long unsigned m=1L; // longest number
for(int i=n; i>=1; i-=2){
m *= i;
}
/*
int i=n;
while(i>1){
m *=i;
i-=2;
}*/
/*
do{
m *=i;
i-=2;
}while(i>1);*/
printf("%hhu!!=%Lu\n",n,m);
}
unsigned my_scanf_to_uchar(unsigned char *puchar){
unsigned retval;
unsigned int uiTemp;
retval = scanf("%u", &uiTemp);
if (retval == 1)
{
if (uiTemp < 256) {
*puchar = uiTemp;
}
else {
retval = 0; //maybe better something like EINVAL
}
}
return retval;
}