dec-c 怎么改语言,在 dec ( C ) 中,循环转换_c_开发99编程知识库

我必须制作一个程序,它读取 2个没有 0的整数,它说是第一个是由第一个环形变换。 例:4123,3412.2341和 1234均由 1234循环变换构成。 下面是我的代码:#include

#include

#include

int main()

{

int last_digit, a, temp, i, b;

int digits = 0, digits1 = 0;

printf("Enter two numbers to test if the second is a circularn");

printf("transformation of the first.");

printf("nn**NOTE**nThe numbers cannon have 0 in their digits.nna=");

scanf("%d", &a);

while (a <= 0)

{

printf("Number must be greater than 0.na=");

scanf("%d", &a);

}

temp = a;

while (temp!=0)

{

digits1++;

temp/=10;

}

printf("b=");

scanf("%d", &b);

while (b <= 0)

{

printf("Number must be greater than 0.nb=");

scanf("%d", &b);

}

while (digits!= digits1)

{

digits = 0;

temp = b;

while (temp!=0)

{

digits++;

temp/=10;

}

if (digits!= digits1)

{

printf("The two numbers must have the same number of digits.nb=");

scanf("%d", &b);

}

}

temp = b;

digits--;

for (i=1;i<=digits1;i++)

{

if (temp == a)

{

printf("%d is a circular transformation of %d",b,a);

return 0;

}

printf("ntemp = %d",temp);

last_digit = temp % 10;

temp = temp/10;

printf("n%dn%d",last_digit,temp);

temp = temp + (last_digit*(pow(10,digits)));

printf("ntemp = %dn",temp);

}

printf("%d is not a circular transformation of %d",b,a);

return 0;

}

在你说什么之前,我必须不用表格和其他东西来做。 只是基本的问题现在我的问题是temp = temp + (last_digit*(pow(10,digits)));

不应该像这样。 如果数字超过 2位,它会告诉我它应该做什么- 1.

我 能 做 些 什么 来 解决 这个 吗?. 它是否与编译器有关? 我从代码块中使用 GCC 。

如果我做temp = temp + (last_digit*(pow(10,digits))) + 1;

对于数字超过 2位的数字,而不是数字为 2位的数字。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值