#include <stdio.h>
int main() {
unsigned long long int num = 285212672; //FYI: fits in 29 bits
int normalInt = 5;
printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
My number is 8 bytes wide and its value is 285212672l. A normal number is 0.
Run Code Online (Sandbox Code Playgroud)
我认为这个意想不到的结果是来自打印unsigned long long int.你怎么printf()了unsigned long long int?
我是C的新手.我尝试为Vector编写函数,但肯定有问题.
这是代码:
/* Defines maths for particles. */
#include <math.h>
#include <stdio.h>
/* The vector struct. */
typedef struct {
long double x, y, z;
} Vector;
Vector Vector_InitDoubleXYZ(double x, double y, double z) {
Vector v;
v.x = (long double) x;
v.y = (long double) y;
v.z = (long double) z;
return v;
}
Vector Vector_InitDoubleAll(double all) {
Vector v;
v.x = v.y = v.z = (long double) all;
return v;
}
Vector Vector_InitLongDXYZ(long double x, long double y, …Run Code Online (Sandbox Code Playgroud) 我有以下代码来实现pow()math.h 库中的 as 。嗯,我有两个问题:
"power:"为什么 scanf() 语句在从 printf() 函数打印之前获取输入?我如何计算大整数的幂,假设计算出的幂如下:22235645654789787978797797(仅作为示例)。我如何计算并打印它。
#include <stdio.h>
unsigned long long int pow(unsigned long long int n,unsigned long long int d);
int main(){
unsigned long long int a,x,n;
printf("Number:");
scanf("%u\n",&a);
printf("power:");
scanf("%u\n",&n);
x = pow(n,a);
printf("%u\n",x);
}
unsigned long long int pow(unsigned long long int n,unsigned long long int d){
if(n+1==1)
return 1;
return d*pow(n-1,d);
}
Run Code Online (Sandbox Code Playgroud)在图像中,您可以看到变量的输入在从 printf()n打印之前获取输入"power:",因此无论您输入什么输入。
请帮助我理解它。欢迎任何建议和意见。