第一题
#include
#include)
int main(void)
{
int a;
printf(“Enter a two-digit number:”);
scanf_s("%d", &a);
printf(“THE : %d%d”,a%10,a/10);
system(“pause”);
return 0;
}
第二题
#include
#include)
int main(void)
{
int a;
printf(“Enter a two-digit number:”);
scanf_s("%d", &a);
printf(“THE : %d%d%d”,a%10,(a/10)%10,(a/10)/10);
system(“pause”);
return 0;
}
第三题
#include
#include)
int main(void)
{
int a,b,c;
printf(“Enter a two-digit number:”);
scanf_s("%1d%1d%1d",&a,&b,&c);//通过限定位宽来实现不按回车输入三个数
printf(“THE reversal: %1d%1d%1d”,c,b,a);
system(“pause”);
return 0;
}
第四题
#include
#include)
int main(void)
{
int a;
printf(“Enter a number between 0 and 32767:”);
scanf_s("%d",&a);
printf(“in octal,your number is: %o”,a);
system(“pause”);
//或者:
//int num10, num8;
//printf("enter a number between 0 and 32767: ");
//scanf("%d", &num10);
//int a, b, c, e, d;
//a = num10 % 8;
//b = (num10 / 8) % 8;
//c = (num10 / 8 / 8) % 8;
//d = (num10 / 8 / 8 / 8) % 8;
//e = (num10 / 8 / 8 / 8 / 8) % 8;
//printf("in octal, your number is: %d%d%d%d%d", e, d, c, b, a);
return 0;
}
第五题
#include
#include)
int main(void)
{
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,b,bb,c;
printf(“Enter the first 11digits of a UPC:”);
scanf_s("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11);
b = a1 + a3 + a5 + a7 + a9 + a11;
bb = a2 + a4 + a6 + a8 + a10;
c = 9-(b * 3 + bb - 1) % 10;
printf(“Check digit: %d\n”,c);
system(“pause”);
return 0;
}
第六题
#include
#include)
int main(void)
{
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,a12,b,bb,c;
printf(“Enter the first 12 digits of a EAN:”);
scanf_s("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &a1, &a2, &a3, &a4, &a5, &a6, &a7, &a8, &a9, &a10, &a11,&a12);
bb = a1 + a3 + a5 + a7 + a9 + a11;
b = a2 + a4 + a6 + a8 + a10+a12;
c = 9-(b * 3 + bb - 1) % 10;
printf(“Check digit: %d\n”,c);
system(“pause”);
return 0;
}