C语言 数组 将一个6位数从低位开始,求出偶数位的数,然后将偶数位的数 组成新数放入变量M中。

如题所述

 

#include<stdio.h>

void main()

{

 int i=0,j,k,n,m[3],M[6],count=0;

 scanf("%d",&n);

 while(n)

 {

    m[i++]=n%10;

    n/=100;

 }

    for(i=0;i<3;i++)

  for(j=0;j<3;j++)

   for(k=0;k<3;k++)

    if(m[i] && i!=j && i!=k && j!=k)

     M[count++]=100*m[i]+10*m[j]+m[k];

   for(i=0;i<count;i++)

    printf("%d\n",M[i]);

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-04-17
#include <stdio.h>
#include <math.h>
int main(void)
{
long x = 0, M = 0;
int i = 0;
printf("\nInput x: ");
scanf("%ld", &x);
while (0 != x)
{
++i;
if (0 == i % 2)
{
M += (x % 10) * (long)pow(10.0, i/2.0 - 1);
}
x /= 10;
}
printf("M = %ld\n", M);
return 0;
}

运行结果:

\Debug>Test.exe
Input x: 123456
M = 135
\Debug>Test.exe
Input x: 246135
M = 263

相似回答
大家正在搜