C语言,这个程序的错误?
#include<stdio.h>voidmain(){inta[5];inttemp;inta;intb;intil;for(inti=0;i<5;i++)scanf(...
#include <stdio.h>
void main()
{
int a[5];int temp;int a;int b;int il;
for(int i=0;i<5;i++)
scanf("%d",&a[i]);
for(a=0;a<5;a++)
{
for(b=0;b<5-a;b++)
{
if(a[b]>a[b+1])
{
temp=a[b];
a[b]=a[b+1];
a[b+1]=a[b];
}
}
}
for(il=0;i<5;il++)
printf("%d",il[il]);
}
There are no conversions to array types, although there are conversions to references or pointers to arrays
c:\users\administrator\desktop\my c project\冒泡,.cpp(7) : error C2446: '<' : no conversion from 'const int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\users\administrator\desktop\my c project\冒泡,.cpp(7) : error C2040: '<' : 'int [5]' differs in levels of indirection from 'const int'
c:\users\administrator\desktop\my c project\冒泡,.cpp(7) : error C2105: '++' needs l-value
c:\users\administrator\desktop\my c project\冒泡,.cpp(9) : error C2113: pointer can only be subtracted from another pointer
c:\users\administrator\desktop\my c project\冒泡,.cpp(20) : error C2109: subscript requires array or pointer type 展开
void main()
{
int a[5];int temp;int a;int b;int il;
for(int i=0;i<5;i++)
scanf("%d",&a[i]);
for(a=0;a<5;a++)
{
for(b=0;b<5-a;b++)
{
if(a[b]>a[b+1])
{
temp=a[b];
a[b]=a[b+1];
a[b+1]=a[b];
}
}
}
for(il=0;i<5;il++)
printf("%d",il[il]);
}
There are no conversions to array types, although there are conversions to references or pointers to arrays
c:\users\administrator\desktop\my c project\冒泡,.cpp(7) : error C2446: '<' : no conversion from 'const int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
c:\users\administrator\desktop\my c project\冒泡,.cpp(7) : error C2040: '<' : 'int [5]' differs in levels of indirection from 'const int'
c:\users\administrator\desktop\my c project\冒泡,.cpp(7) : error C2105: '++' needs l-value
c:\users\administrator\desktop\my c project\冒泡,.cpp(9) : error C2113: pointer can only be subtracted from another pointer
c:\users\administrator\desktop\my c project\冒泡,.cpp(20) : error C2109: subscript requires array or pointer type 展开
4个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a[5];
int temp;
int b;
int c;
int i;
for(i=0;i<5;i++)
scanf("%d",&a[i]);
for(b=0;b<5-1;b++)
{
for(c=0;c<5-1;c++)
{
if(a[c]>a[c+1])
{
temp=a[c];
a[c]=a[c+1];
a[c+1]=temp;
}
}
}
for(i=0;i<5;i++)
printf("%d",a[i]);
system("pause");
return 0;
}
展开全部
太粗心了吧,先是变量i没定义,然后做交换的循环错误,大循环for(a=1;a<5;a++)
for(b=0;b<5-a;b++)
交换语句的第三句又错了,看看清楚谁和谁交换,还有相当无语,最后一句输出语句的数组名字也错了,,亲!你编的时候在干嘛!!
for(b=0;b<5-a;b++)
交换语句的第三句又错了,看看清楚谁和谁交换,还有相当无语,最后一句输出语句的数组名字也错了,,亲!你编的时候在干嘛!!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
数组a和int a的名字一样了,不能这么起名。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
temp=a[b];a[b]=a[b+1];a[b+1]=a[b]; 该句有问题 il数组没定义。等
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询