C语言编程改错

1
一元以下的硬币中有一角、二角、五角三种,列举出将一元换成硬币的所有方法。
I,j,k分别存放五角,二角,一角面值的硬币数量。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main()
{ float i,j,k;
/************found************/
for(i=1;i<=2;i++)
for(j=0;j<=5;j++)
for(k=0;k<=10;k++)
/************found************/
{ if(i*0.5+j*0.2+k*0.1==1)
printf("%.0f,%.0f,%.0f\n",i,j,k);
}
}

2
输入五个互质整数,将它们存入数组a中,再输入1个整数x,然后再数组中查找x。如果找到,则输出相应的下标,否则输出“not found”。
如输入:1 2 3 4 5,3,则输出3 is in 2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main()
{ int a[5],x;
int i;
printf("请输入5个数:\n");
for(i=0;i<5;i++)
/************found************/
scanf("%d",a[i]);
printf("请输入x:\n");
scanf("%d",&x);
for(i=0;i<5;i++)
if(a[i]==x)break;
/************found************/
if(a[i]==x)printf("%d is in %d",x,i);
else printf("not found!");
}
3
将【m,n】之间的所有素数存放在一维数组a中,并输出这些素数。
例如,如果m=2,n=20,程序的输出应为:
2 3 5 7
11 13 17 19
#include <math.h>
#include <stdio.h>
main()
{ int a[100],i,j,k,m,n,c=0;
printf("Please enter m,n(m<n):");
scanf("%d,%d",&m,&n);
/************found************/
for ( i=m; i<=100; i++)
{
k=sqrt(i);
for ( j=2; j<=k; j++)
/************found************/
if (j % i == 0)
break;
if(j >= k+1)
a[c++] = i;
}
for (i=0; i<c; i++)
{ printf("%4d",a[i]);
if ((i+1) % 4 == 0) printf("\n");
}
}
4
打印输出以下图形
*
***
*****
*******
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main()
{ int i,j;
for(i=1;i<=5;i++)
/************found************/
{ printf('\n');
for(j=1;j<=10-i;j++)
printf(" ");
/************found************/
for(j=1;j<=2*i+1;j++)
printf("*");
}
printf("\n");
}
5
女儿今年12岁,父亲比女儿大30岁,计算出父亲在多少年后比女儿年龄大一倍,那时他们的年龄各是多少?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
main()
{ int father,daughter;
int i;
daughter=12;
/************found************/
father=30;
/************found************/
for(i=1;father!=2*daughter;i++)
{ daughter++;
father++;
}
printf("After %d years,father's age is twice to daughter's age\n",i);
printf("Their ages are %d and %d\n",father,daughter);
}

第1个回答  2010-07-02
NO
相似回答