当前位置:网站首页>Noi OJ 1.3 13: reverse output of a three digit C language

Noi OJ 1.3 13: reverse output of a three digit C language

2022-06-23 10:29:00 chd44

describe

Invert a three digit output .

Input

A three digit number n.

Output

Reverse output n.

This kind of question is not difficult , But thinking should be flexible , Here are two ideas .

Method 1: First find the number of hundreds , Remove one more bit , Find out the ten digits , Finally, subtract the hundreds and tens from the original number , Get single digits , One by one ( Stupid way ).

#include<stdio.h>
int main(){
int a;
scanf("%d",&a);
int b=a/100;
int c=a/10-b*10;
int d=a-c*10-b*100;
printf("%d%d%d",d,c,b);
return 0;
}

Method 2: Find a bit in the way of remainder , The ten bits are divided by an integer 10 After seeking remainder , Direct division of hundreds 100 Just go ( A slightly smarter approach )

#include<stdio.h>
int main(){
int a,b,c,d;
scanf("%d",&a);
b=a%10;
c=(a/10)%10;
d=a/100;
printf("%d%d%d",b,c,d);
return 0;
}

原网站

版权声明
本文为[chd44]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231012356414.html