c语言sized函数,C语言习题 函数.doc

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值