printf格式化问题
#include <stdio.h>#include <stdlib.h>
#include <math.h>
double Area(double a , double b ,double c)
{
double s;
double area;
s = (a + b + c)/(2.0);
area = sqrt( s * ( s - a ) * (s - b) * (s - c));
return area;
}
int main(void)
{
int TrangCount;
printf("平方:%f",pow(2,4));
scanf("%d",&TrangCount);
double PointSum;
for(int i = 0; i <TrangCount;i++)
{
scanf("%d %d",&PointSum, &PointSum);
printf("Pointsum%d %d\n",PointSum,PointSum);
}
printf("Pointsum%d %d\n",PointSum,PointSum);
double AllLine;
int LineCount = 0;
for(int i = 0; i <= TrangCount - 2; i ++)
{
for(int j = i + 1; j <= TrangCount - 1; j++)
{
printf("ForPointsum%d %d\n",PointSum,PointSum);
AllLine = ((double)((PointSum - PointSum) * (PointSum - PointSum) +
(PointSum - PointSum) * (PointSum - PointSum)));
printf(" qianbanbufen: %d %d %d %d\n",PointSum ,PointSum, PointSum, PointSum);
printf(" sqrt%d m\n",(PointSum - PointSum)*(PointSum - PointSum) );
printf("PointSum - PointSum%d\n",(PointSum - PointSum));
printf("(PointSum - PointSum)*(PointSum - PointSum) %d\n",(PointSum - PointSum)*(PointSum - PointSum));
printf("shishu %d\n",32 * 32);
printf("%lfAllLIne\n",AllLine);
LineCount++;
}
}
double biggest = 3;
double New;
for(int one = 0; one <= LineCount - 3;one++)
{
for(int two = one + 1; two <= LineCount - 2;two++)
{
for(int three = two + 1;three <= LineCount - 1;three++)
{
New= Area(AllLine,AllLine,AllLine);
printf("one:%d two:%d three;%d New:%d%d %d %d \n",one ,two ,three,New,AllLine,AllLine,AllLine);
if( biggest < New)
{
biggest = New;
}
}
}
}
printf("%f",biggest);
return 0;
}
为什么printf("PointSum - PointSum%d\n",(PointSum - PointSum)); %d显示的不是0,
而 printf("(PointSum - PointSum)*(PointSum - PointSum) %d\n",(PointSum - PointSum)*(PointSum - PointSum));%d而是0 您好,关于您提出的问题,请问具体是什么方面的问题?是关于printf函数的格式化字符串吗?
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 是的
davidmou 发表于 2023-12-07 23:08
是的
好的,下面是关于printf函数格式化字符串的一些常见用法:
1. 打印整数:%d
例:
int num = 10;
printf("这是一个整数:%d\n", num);
2. 打印浮点数:%f
例:
double pi = 3.14159;
printf("这是一个浮点数:%f\n", pi);
3. 打印字符:%c
例:
char ch = 'A';
printf("这是一个字符:%c\n", ch);
4. 打印字符串:%s
例:
char str[] = "Hello World";
printf("这是一个字符串:%s\n", str);
5. 打印十六进制数:%x(小写字母)/%X(大写字母)
例:
int hex = 255;
printf("这是一个十六进制数:%x\n", hex);
6. 打印指针地址:%p
例:
int *ptr = #
printf("这是一个指针地址:%p\n", ptr);
7. 控制打印宽度和精度
可以使用数字来控制打印的宽度和小数位数。
例:
double num = 3.14159;
printf("宽度为6,小数位数为2的浮点数:%6.2f\n", num);
这些只是printf函数格式化字符串的一些基本用法,更详细的用法可以查阅相关资料。希望能够帮到您!
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
页:
[1]