相关疑难解决方法(0)

"mod"和"remaining"之间有什么区别?

我的朋友说"mod"和"rest"之间存在差异.

如果是这样,那么C和C++的差异是什么?"%"是指C中的"mod"还是"rem"?

c math operators

116
推荐指数
4
解决办法
10万
查看次数

为什么我的电源操作员(^)不工作?

#include <stdio.h>

void main(void)
{
    int a;
    int result;
    int sum = 0;
    printf("Enter a number: ");
    scanf("%d", &a);
    for( int i = 1; i <= 4; i++ )
    {
        result = a ^ i;

        sum += result;
    }
    printf("%d\n", sum);
}
Run Code Online (Sandbox Code Playgroud)

我不知道为什么这个'^'不起作用.

c c++

48
推荐指数
2
解决办法
19万
查看次数

使用我的编译器和操作系统时,为什么当n = 5时pow(n,2)返回24?

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n,i,ele;
    n=5;
    ele=pow(n,2);
    printf("%d",ele);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出是24.

我在Code :: Blocks中使用GNU/GCC.

怎么了?

我知道pow函数返回一个double,但是25适合一个int类型所以为什么这个代码打印24而不是25?如果n=4; n=6; n=3; n=2;代码有效,但有五个代码没有.

c math.h c-standard-library

23
推荐指数
1
解决办法
4809
查看次数

为什么在C++中pow(10,5)= 9,999

最近我写了一段代码:

const int sections = 10;

for(int t= 0; t < 5; t++){
   int i = pow(sections, 5- t -1);  
   cout << i << endl;
}
Run Code Online (Sandbox Code Playgroud)

结果是错误的:

9999
1000
99
10
1
Run Code Online (Sandbox Code Playgroud)

如果我只使用这个代码:

for(int t = 0; t < 5; t++){
    cout << pow(sections,5-t-1) << endl; 
}
Run Code Online (Sandbox Code Playgroud)

问题不再发生:

10000
1000
100
10
1
Run Code Online (Sandbox Code Playgroud)

有没有人给我解释?非常感谢你!

c++ mingw pow

11
推荐指数
2
解决办法
8344
查看次数

为什么gcc编译器输出pow(10,2)为99而不是100?

#include <iostream.h>
#include <math.h>
int main()
{
    int j=2;
    int output;
    output=pow(10,j);
    cout<<output;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我把上面的代码写到gcc 12编译器,得到输出99而不是100.我在搜索各种网站时没有得到正确的理由.有编译器问题吗?

c++ gcc

3
推荐指数
1
解决办法
3025
查看次数

为什么pow(10,2)99而不是100的结果?

我正在用c制作一个新项目,功能"不起作用".我该怎么做才能解决?

它的功能实际为2到10的幂,但10的功率为1

#include <stdio.h>
#include <math.h>

int main(){
    int res=2;
    int base=10;
    int exp=2;
    res= pow(base,exp);
    printf("%d",res);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我希望输出为100,但输出为99

c

-2
推荐指数
1
解决办法
245
查看次数

为什么pow(5,2)变成了24?

我正在制作一个简单的计算器,你可以选择一个功能,然后2个输入来得到你的答案.这是一个简洁的小程序,除了权力之外,一切都运行顺畅.每个号码都正常工作.

但根据这个:5^2=24, 5^3=624.我在用pow(number1,number2).

#include <iostream>
#include<math.h>

using namespace std;

int main()
{
    for(;;){
    int func;
    int number1;
    int number2;
    cout << "Input your function (+,-,x,/,Square,Power)(1,2,3,4,5,6) ";
    cin >> func;
    cout << "input #1: ";
    cin >> number1;
    cout << "input #2: ";
    cin >> number2;
    if (func==1){
        int answer;
        answer = number1 + number2;
        cout << number1 << " + " << number2 << " = " << answer << endl;
    }
    else {
            if (func==2){ …
Run Code Online (Sandbox Code Playgroud)

c++ calculator pow

-10
推荐指数
1
解决办法
3219
查看次数

标签 统计

c ×4

c++ ×4

pow ×2

c-standard-library ×1

calculator ×1

gcc ×1

math ×1

math.h ×1

mingw ×1

operators ×1