帮我编写一个求最大值的c语言代码
时间: 2023-04-08 18:04:49 浏览: 64
好的,以下是一个简单的求最大值的C语言代码:
```
#include <stdio.h>
int main() {
int num1, num2, num3, max;
printf("请输入三个整数:\n");
scanf("%d %d %d", &num1, &num2, &num3);
max = num1;
if (num2 > max) {
max = num2;
}
if (num3 > max) {
max = num3;
}
printf("最大值是:%d\n", max);
return 0;
}
```
希望能对你有所帮助!
相关问题
编写一个链表求出最大值的代码使用c语言编写
好的,以下是用C语言编写求链表最大值的代码:
```
#include <stdio.h>
#include <stdlib.h>
struct Node {
int value;
struct Node *next;
};
int main() {
// 创建链表
struct Node *head = (struct Node*)malloc(sizeof(struct Node));
head->value = 0; // 头节点的值为0
head->next = NULL; // 头节点的next为NULL
// 向链表中添加节点
struct Node *p = head;
for (int i=1; i<=5; i++) {
struct Node *temp = (struct Node*)malloc(sizeof(struct Node));
temp->value = i;
temp->next = NULL;
p->next = temp;
p = temp;
}
// 遍历链表,求最大值
int max_val = head->next->value;
p = head->next->next;
while (p != NULL) {
if (p->value > max_val) {
max_val = p->value;
}
p = p->next;
}
// 输出结果
printf("最大值为:%d\n", max_val);
return 0;
}
```
帮我编写一个判断3个数中的最大值的c语言代码
```
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入3个数,用空格隔开:\n");
scanf("%d%d%d", &a, &b, &c);
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
printf("最大值为:%d\n", max);
return 0;
}
```