本文目录一览:
- c语言程序挑错
- c语言问题~帮忙挑一下错吧!!
- [帮忙在此程序中挑错呀~~~(c语言 急!!!)](#帮忙在此程序中挑错呀~~~(c语言 急!!!))
c语言程序挑错
第五行 for(j=0;i6;j++)
改为 for(j=0;j6;j++)
还有最好加上以下头文件:
#include <stdlib.h> // rand()头文件
#include <time.h> // time()头文件
#include <conio.h> // getch()头文件
我在 VC 上运行的程序:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
main() {
int a[5][6], i, j, max, min, t; // 只用变量max, min 使得程序简练
for (i = 0; i < 5; i++) {
for (j = 0; j < 6; j++) { // 注意是j, 不能是i
a[i][j] = rand() % 100 + 1;
printf("%-4d", a[i][j]);
}
printf("\n");
}
printf("\n");
max = a[0][0]; // 存放最大值
min = a[0][0]; // 存放最小值
for (i = 0; i < 5; i++)
for (j = 0; j < 6; j++) {
if (a[i][j] > max) // 找最大值, 如果成立, 就一定不是最小值
max = a[i][j];
else if (a[i][j] < min) // 找最小值
min = a[i][j];
}
t = a[0][5]; // 互换最大值和
a[0][5] = max;
max = t;
t = a[4][0]; // 互换最小值和
a[4][0] = min;
min = t;
for (i = 0; i < 5; i++) {
for (j = 0; j < 6; j++)
printf("%-4d", a[i][j]);
printf("\n");
}
printf("\n");
getch(); // 可以去掉, 不知道你写着是什么意思
}
c语言问题~帮忙挑一下错吧!!
#include <stdio.h>
#include <string.h>
int main() {
void strcate(char str1[], char str2[]);
char str1[30], str2[30];
gets(str1);
gets(str2);
puts(str1);
puts(str2);
strcate(str1, str2);
puts(str1);
return 0;
}
void strcate(char str1[], char str2[]) {
strcat(str1, str2);
}
帮忙在此程序中挑错呀~~~(c语言 急!!!)
#include <stdio.h> // 输入法错误 # 英文
#include <stdlib.h> // 同上
int main() {
int a[3][5], x, y, i, j, k;
int max, min;
for (i = 0; i < 3; i++)
for (j = 0; j < 5; j++)
scanf("%d", &a[i][j]); // 加上 &
for (i = 0; i < 3; i++) {
max = a[i][0]; y = 0;
for (k = 1; k < 5; k++) // 加上括号
{
if (max < a[i][k]) // i 和 k位置反了
{
y = k;
max = a[i][k];
}
}
min = a[i][y];
x = i;
for (k = 0; k < 3; k++)
if (min > a[k][y])
{
x = k;
min = a[k][y];
}
if (i == x)
printf("a[%d][%d]=%d is andian\n", x, y, a[x][y]);
}
return 0; // 函数正常执行应返回0值
}