符号问题(应该是这么说吧)
#include<stdio.h>void main()
{
void abc(int arr[],int n);
int i;
int array;
printf("please enter the twenty number:\n");
for(i=0;i<20;i++)
scanf("%d",&array);
abc(array,20);
printf("\n");
}
voidabc(int arr[],int n)
{
int count,b,i;
count=0,b=0;
while(b<n)
{
for(i=0;i<n;i++)
if(arr!=0)
{ count++;
if(count==5)
printf("%3d",arr);-------->printf("%3d",arr中括号i);这里是这样的怎么显示不出来
arr=0;------------------->arr中括号i=0;
count=0;
b++;
}
}
}
为什么在if(count==5) 这个语句中,不用{}括起下面那四句,程序会无答案输出呢? 如果不加{},if语句只控制下面一句...
if(count==5)
printf("%3d",arr);
每次循环,你都让count = 0,count再怎么++也不会==5丫
PS.下次贴代码时..请用[#code]这里是代码[#/code]...使用时去掉"#" 同一的程序换一种写法:
#include<stdio.h>
main()
{
void left(int *p,int n);
int num,n,i;
printf("how many people?\\n");
scanf("%d",&n);
for(i=0;i<n;i++)
num=i+1;
left(num,n);
for(i=0;i<n;i++)
if(num!=0)
printf("no.which left last is %d",num);
}
void left(int *p,int n)
{
int i,out,count;
i=0;
out=0;
count=0;
while(out<n-1)
{
if(*(p+i)!=0)
count++;
if(count==5)
{
*(p+i)=0;
count=0;
out++;
}
i++;
if(i==n) i=0;
}
}
为什么最后要加上if(i==n) i=0; 呢?不加就无法正确运行。为什么会这样?而且不加的时候还会使主函数最后一个for中的printf语句打印数次,但通过函数中的操作,不是已经将最后一个以外的都置零了吗? 没有这一句的话,在最后的取数循环中(*(p+i)!=0将不在N的范围之类
页:
[1]