如何使我的输出有空格(偶数和奇数) [英] How to make my output have space(even and odd number )
本文介绍了如何使我的输出有空格(偶数和奇数)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include< stdio.h>
#include< conio.h>
#define BILMAX 10
int main()
{
int num [BILMAX],i;
printf(insert 10 number and separated by space:\\\
);
for(i = 0; i <10; i ++)
{
scanf(%d,& num [i]);}
printf n \\\
Even Number:\\\
);
for(i = 0; i <10; i ++)
{
if(num [i]%2 == 0)
printf(%d,num [一世]);
}
printf(\\\
\\\
Odd Number:\\\
);
for(i = 0; i <10; i ++)
{
if(num [i]%2!= 0)
printf(%d,num [一世]);
}
getch();
return 0;
}
我的输出如下 / strong>
插入10号码并以空格分隔:
1 2 3 4 5 6 7 8 9 10
偶数:
246810
奇数:
13579
strong>
插入10数字,并以空格分隔:/ p>
1 2 3 4 5 6 7 8 9 10
偶数:
2 4 6 8 10
奇数:
1 3 5 7 9
我希望我的输出有空格。 b
$ b
解决方案
>如果要在每个数字后面打印一个空格,请更改此行:
printf(%d,num [i ]);
到
printf(%d,num [i]);
注意%d
后的空格。 / p>
#include < stdio.h >
#include < conio.h >
#define BILMAX 10
int main()
{
int num[BILMAX],i;
printf("insert 10 number and separated by space:\n");
for (i = 0;i<10;i++)
{
scanf("%d",&num[i]);}
printf("\n\nEven Number : \n");
for(i = 0; i < 10; i++)
{
if(num[i] % 2==0)
printf("%d",num[i]);
}
printf("\n\nOdd Number : \n");
for(i = 0;i < 10; i++)
{
if(num[i] % 2 !=0)
printf("%d",num[i]);
}
getch();
return 0;
}
my output is like this
insert 10 number and separated by space:
1 2 3 4 5 6 7 8 9 10
Even Number:
246810
Odd Number:
13579
i want my output like this
insert 10 number and separated by space:
1 2 3 4 5 6 7 8 9 10
Even Number:
2 4 6 8 10
Odd Number:
1 3 5 7 9
i want my output have a space.
Please help
解决方案
If you want to print a space after each number, change this line:
printf("%d",num[i]);
to
printf("%d ",num[i]);
Notice the space after %d
.
这篇关于如何使我的输出有空格(偶数和奇数)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文