2e-1 为 1.0^(-1)*2
在顺序查找法中,如果要从n个学生中找到某个特定的学生信息,最坏的情况是这个学生是最后一个被比较的,这时需要比较n次。但是,如果学生是均匀分布的,那么平均来说,你会在列表的中间找到这个学生,也就是大约n/2次比较。
k = i -- 含义:k = i = i - 1
#include<stdio.h>
int main()
{
float price;
int num;
printf("请输入商品的单价和数量:\n");
scanf("%f%d",&price,&num);
float sum_orl=num*1.0*price;
printf("原总价:%.2f",sum_orl);
float cmp=sum_orl;
if(num==2)
{
sum_orl*=0.85;
}
if(num>=3)
{
sum_orl*=0.7;
}
float sum_lar=sum_orl;
while(sum_orl>=300)
{
sum_lar=sum_lar-30;
sum_orl=sum_orl-300;
}
printf("折扣后总价:%.2f\n",sum_lar);
printf("客户已经享受的优惠:%.2f",cmp-sum_lar);
return 0;
}
#include<stdio.h>
int main()
{
int i;
scanf("%d", &i);
if (i % 2 == 1)
{
int num = i;
float sum = 0, pnum;
while (i)
{
scanf("%f", &pnum);
sum = sum + pnum;
i--;
}
sum = sum / (1.0 * num);
printf("中位数为:%.2f", sum);
}
else
{
float a[100000], temp = 0;
int m = 0,n=0;
for (m = 0; m <= i - 1; m++)
{
scanf("%f", &a[m]);
}
for (n = 0; n <= i - 2; n++)//共n个数,循环n-1次一定能完成操作
{
for (m = 0; m <= i - 2; m++)
{
if (a[m] > a[m + 1])//2024与2023,2024应该要在后面,strcmp函数结果为>0,此时进行交换
{
temp = a[m];
a[m] = a[m + 1];
a[m + 1] = temp;
}
}
}
printf("中位数为:%.2f", (a[i / 2] + a[(i / 2) - 1]) / 2.0);
}
return 0;
}