Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

c++ - 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("

Even Number : 
");
for(i = 0; i < 10; i++)
{
if(num[i] % 2==0)
printf("%d",num[i]);
}
printf("

Odd Number : 
");
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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...