1.编bool型函数,判断二维空间中的某点是否优于另一点。优于关系定义为:在二维空间中,某点(A1,A2)优于(B1,B2),当且仅当A1>B1,A2>B2
#include <stdio.h>
#include <stdbool.h>
typedef struct point{
float x;
float y;
}point;
bool bigpoint(struct point *p1,struct point *p2){
if(p1->x>p2->x&&p1->y>p2->y)
return true;
return false;
}
2.编程序,统计以100为结束符的整数输入流中-1,0,+1的出现次数并输出
#include <stdio.h>
int main(){
int temp;
scanf("%d",&temp);
int count0=0,count1=0,countd1=0;
while(temp!=100){
if(temp==1)
count1++;
else if(temp==-1)
countd1++;
else if(temp==0)
count0++;
scanf("%d",&temp);
}
printf("count0 = %d count1 = %d count-1 = %d",count0,count1,countd1);
}
3.编写字符型递归函数digit(n,j),求整数n的从右边开始的第j个数字字符
#include <stdio.h>
int digit(int n,int j){
if(j==1)
return (n%10)+'0';
else
return digit(n/10,j-1);
}
int main(){
char temp = digit(12345,2);
printf("%c",temp);
}
4.平面上有100个点,任意三个点均可构成三角形,编写程序,输入一个点的坐标,求面积最大的三角形,及其面积,面积公式
#include <stdio.h>
#include <math.h>
typedef struct Point{
double x;
double y;
} Point;
double calculateDistance(struct Point p1, struct Point p2) {
double dx = p2.x - p1.x;
double dy = p2.y - p1.y;
return sqrt(dx * dx + dy * dy);
}
double calculateTriangleArea(struct Point p1, struct Point p2, struct Point p3) {
double a = calculateDistance(p1, p2);
double b = calculateDistance(p1, p3);
double c = calculateDistance(p2, p3);
double s = (a + b + c) / 2.0;
return sqrt(s * (s - a) * (s - b) * (s - c));
}
int main() {
struct Point points[10];
int i, j, k;
double maxArea = 0.0;
struct Point p1, p2, p3;
printf("请输入100个点的坐标:\n");
for (i = 0; i < 10; i++) {
printf("请输入第 %d 个点的 x 坐标:", i + 1);
scanf("%lf", &points[i].x);
printf("请输入第 %d 个点的 y 坐标:", i + 1);
scanf("%lf", &points[i].y);
}
for (i = 0; i < 10; i++)
for (j = i + 1; j < 10; j++)
for (k = j + 1; k < 10; k++) {
double area = calculateTriangleArea(points[i], points[j], points[k]);
if (area > maxArea) {
maxArea = area;
p1 = points[i];
p2 = points[j];
p3 = points[k];
}
}
printf("面积最大的三角形的顶点坐标为:\n");
printf("P1: (%.2lf, %.2lf)\n", p1.x, p1.y);
printf("P2: (%.2lf, %.2lf)\n", p2.x, p2.y);
printf("P3: (%.2lf, %.2lf)\n", p3.x, p3.y);
printf("面积最大的三角形的面积为:%.2lf\n", maxArea);
return 0;
}
5.建立一个字符链表,要求
设计用于存储结点的数据类型
编函数建立链表,按顺序保存26个大写字母
#include <stdio.h>
#define N 26
typedef struct node {
char ch;
struct node *next;
} node;
struct node* create() {
struct node *head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
for(int i=0; i<N; i++) {
struct node *p=(struct node*)malloc(sizeof(struct node));
p->ch='z'-i;
p->next=head->next;
head->next=p;
}
return head->next;
}