诚心询问一个关于C语言pow用法的有关问题
诚心询问一个关于C语言pow用法的问题
我想设计一个小程序从一个12位的数字中分别选出每一个。我写了下面的程序。但是系统跳出这个错误提示:“invalid operands to binary expression ('double' and 'double')”请问是怎么回事?
#include<stdio.h>
#include<math.h>
int main (void){
long long UPC;
int upc1,upc2,upc3,upc4,upc5,upc6,upc7,upc8,upc9,upc10,upc11,upc12;
printf("UPC Validator\n"
"=============\n"
"UPC (0 to quit): ");
scanf("%lld",&UPC);
upc1 = (UPC - UPC % pow(10,11))/pow(10,12);
upc2 = (UPC % pow(10,11) - UPC % pow(10,10))/pow(10,11);
upc3 = (UPC % pow(10,10) - UPC % pow(10,9))/pow(10,10);
upc4 = (UPC % pow(10,9) - UPC % pow(10,8))/pow(10,9);
upc5 = (UPC % pow(10,8) - UPC % pow(10,7))/pow(10,8);
upc6 = (UPC % pow(10,7) - UPC % pow(10,6))/pow(10,7);
upc7 = (UPC % pow(10,6) - UPC % pow(10,5))/pow(10,6);
upc8 = (UPC % pow(10,5) - UPC % pow(10,4))/pow(10,5);
upc9 = (UPC % pow(10,4) - UPC % pow(10,3))/pow(10,4);
upc10 =(UPC % pow(10,3) - UPC % pow(10,2))/pow(10,3);
upc11 = (UPC % 100 - UPC % 10) / 100;
upc12 = UPC % 10;
printf("this is a valid UPC.\n The company code is %d%d%d%d%d%d\n The product code is %d%d%d%d%d\n",upc1,upc2,upc3,upc4,upc5,upc6,upc7,upc8,upc10,upc11);
return 0;
------解决思路----------------------
取模运算符(%)只能用于整数。pow的返回值是浮点数。
------解决思路----------------------
------解决思路----------------------
我想设计一个小程序从一个12位的数字中分别选出每一个。我写了下面的程序。但是系统跳出这个错误提示:“invalid operands to binary expression ('double' and 'double')”请问是怎么回事?
#include<stdio.h>
#include<math.h>
int main (void){
long long UPC;
int upc1,upc2,upc3,upc4,upc5,upc6,upc7,upc8,upc9,upc10,upc11,upc12;
printf("UPC Validator\n"
"=============\n"
"UPC (0 to quit): ");
scanf("%lld",&UPC);
upc1 = (UPC - UPC % pow(10,11))/pow(10,12);
upc2 = (UPC % pow(10,11) - UPC % pow(10,10))/pow(10,11);
upc3 = (UPC % pow(10,10) - UPC % pow(10,9))/pow(10,10);
upc4 = (UPC % pow(10,9) - UPC % pow(10,8))/pow(10,9);
upc5 = (UPC % pow(10,8) - UPC % pow(10,7))/pow(10,8);
upc6 = (UPC % pow(10,7) - UPC % pow(10,6))/pow(10,7);
upc7 = (UPC % pow(10,6) - UPC % pow(10,5))/pow(10,6);
upc8 = (UPC % pow(10,5) - UPC % pow(10,4))/pow(10,5);
upc9 = (UPC % pow(10,4) - UPC % pow(10,3))/pow(10,4);
upc10 =(UPC % pow(10,3) - UPC % pow(10,2))/pow(10,3);
upc11 = (UPC % 100 - UPC % 10) / 100;
upc12 = UPC % 10;
printf("this is a valid UPC.\n The company code is %d%d%d%d%d%d\n The product code is %d%d%d%d%d\n",upc1,upc2,upc3,upc4,upc5,upc6,upc7,upc8,upc10,upc11);
return 0;
------解决思路----------------------
取模运算符(%)只能用于整数。pow的返回值是浮点数。
------解决思路----------------------
#include <stdio.h>
__int64 mypow(int b,int e) {
int i;
__int64 v;
v=1i64;
for (i=0;i<e;i++) v*=b;
return v;
}
int main () {
__int64 UPC;
__int64 upc1,upc2,upc3,upc4,upc5,upc6,upc7,upc8,upc9,upc10,upc11,upc12;
printf("UPC Validator\n"
"=============\n"
"UPC (0 to quit): ");
scanf("%I64d",&UPC);
upc1 = (UPC - UPC % mypow(10,11))/mypow(10,12);
upc2 = (UPC % mypow(10,11) - UPC % mypow(10,10))/mypow(10,11);
upc3 = (UPC % mypow(10,10) - UPC % mypow(10,9))/mypow(10,10);
upc4 = (UPC % mypow(10,9) - UPC % mypow(10,8))/mypow(10,9);
upc5 = (UPC % mypow(10,8) - UPC % mypow(10,7))/mypow(10,8);
upc6 = (UPC % mypow(10,7) - UPC % mypow(10,6))/mypow(10,7);
upc7 = (UPC % mypow(10,6) - UPC % mypow(10,5))/mypow(10,6);
upc8 = (UPC % mypow(10,5) - UPC % mypow(10,4))/mypow(10,5);
upc9 = (UPC % mypow(10,4) - UPC % mypow(10,3))/mypow(10,4);
upc10 =(UPC % mypow(10,3) - UPC % mypow(10,2))/mypow(10,3);
upc11 = (UPC % 100i64 - UPC % 10i64) / 100i64;
upc12 = UPC % 10i64;
printf("this is a valid UPC.\n The company code is %i64d%i64d%i64d%i64d%i64d%i64d\n The product code is %i64d%i64d%i64d%i64d%i64d\n",upc1,upc2,upc3,upc4,upc5,upc6,upc7,upc8,upc10,upc11);
return 0;
}
------解决思路----------------------
int i;
long long temp;
int upc[12];