使用C语言的除法和取模运算符将数字按照相反的顺序打印出来
Problem
How to print the given two-digit number in reverse order with the help of division and Modulo operator using C programming language?
Solution
So far, we had seen how to reverse the string using string function and without string function. Now let’s see how to reverse the two-digit number without using the predefined function.
The logic we use to reverse the number with the help of operators is −
int firstno=number%10; //stores remainder int secondno=number/10;// stores quotient登录后复制
程序 1
在这个例子中,我们将取一个两位数,并应用除法和取模运算符来逆转数字−
#include int main(){ int number; printf("enter a number:"); scanf("%4d",&number); int firstno=number%10; //stores remainder int secondno=number/10;// stores quotient printf("After reversing =%d%d