1. 将程序填写完整,使程序输出100到999之间所有能被7整除且左右对称的数。
例如:707就是满足条件的数。
#include
#include
void main()
{
/**/ /**/
int k;
for(k=100; k<=999; k++)
find( k );
getch();
}
void find(int m)
{
int a,b;
if(/**/ /**/)
{
a=m%10;
/**/ /**/
if(a==b) printf("%d\n",m);
}
}
2. 将程序填写完整,使其中函数chg能够将一个数组的元素循环左移1个位置,第一个元素存到末尾。
例如:数组元素为 1 2 3 4 5 6 7 8 9 10
则该数组元素循环左移后变为 2 3 4 5 6 7 8 9 10 1
#include
#include
void chg(/**/ /**/ )
{
int i,temp;
temp=arr[0];
for(i=0; i
arr[i]=/**/ /**/
arr[n-1]=temp;
}
void main()
{
int a[10],i;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
chg(a,10);
for(i=0;i<10;i++)
printf("%d ",a[i]);
getch();
}
3. 将程序填写完整,用递归算法求13+23+33+…+n3的值。
#include
#include
long int fun(int n)
{
long int k;
if(/**/ /**/ )
k=1;
else
k=/**/ /**/
return (k);
}
void main()
{
int i;
printf("Input data:");
scanf("%d",&i);
if(i<0)
printf("Input data ereor!");
else
printf("Sum=%ld\n",fun(i));
getch();
}
4. 将程序填写完整,使其中函数chg能够求3*3矩阵的转置矩阵。
例如:矩阵
2 3
5 6
8 9
转置后变成:
4 7
5 8
6 9
#include
#include
int chg(/**/ /**/)
{
int i,j,temp;
for(/**/ /**/)
for(j=i+1;j<3;j++)
{
temp=array[i][j];
array[i][j]=array[j][i];
/**/ array[j][i]=temp; /**/
}
}
void main()
{
int i,j;
int array[3][3];
printf("Input array:\n");
for(i=0;i<3;i++)
for(j=0; j<3; j++) scanf("%7d",&array[i][j]);
chg(array);
printf("Reversed array:\n");
for(i=0;i<3;i++)
{
for(j=0; j<3; j++) printf("%d ",array[i][j]);
printf("\n");
}
getch();
}
5. 修改程序,使函数fun(int n) (n从3开始)计算如下分数之和。
例如,n=8时:
#include
/**/ fun( int n ) /**/
{
double x = 0.0;
int i,sgn=1;
for(i=3;i<=n;i++)
{x+=sgn/(5+/**/ 3*i /**/);
sgn=sgn*(-1);
}
retu