第四次作业

1.a.用//在同一行中进行注释。用/*和*/在一段中进行注释。

b.用for,while等即使只有一行代码也尽量使用{}

c.合理利用缩进,让代码看起来更清晰

d.定义变量名尽量清晰

2.a.for

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int n; 
	scanf("%d",&n);
	int i;
	int sum;
	for(i=1;i<=n;i++){
		sum=sum*i;
	}
	printf("n!=%d",sum);
	return 0;
}

 b.while 

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int n; 
	scanf("%d",&n);
	int i=1;
	int sum=1;
	while(i<=n){
		sum=sum*i;
		i++;
	}
	
	
	printf("n!=%d",sum);
	return 0;
}

c.do-while

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int n; 
	scanf("%d",&n);
	int i=1;
	int sum=1;
	do
	{
		sum=sum*i;
		i++;
	}while(i<=n);
	
	
	printf("n!=%d",sum);
	return 0;
}

3.

#include <stdio.h>

int main() {
	int k=1;
	double i;
	double sum=1; 
	int a;
	for(a=-1;i>= 1e-7||i<=1e-7;a=-a){
        int b;
        b=2k+1;
		i=a*k/b;
		sum=sum+i;
		k++;
	}
	printf("%f",sum*4);
	return 0;
}

4.

#include <stdio.h>
#include <stdlib.h>

int main() 
{
	int i=1,a=0,b=1,c; 
	printf("0,1");
	while(i<19){
		c=a+b;
		a=b;
		b=c;
		printf(",%d",c);
		i++;
	}
	return 0;
}

5.a.

#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int n,b;
	scanf("%d",&n);
	while(n>0){
		b=n%10;
		printf("%d",b);
		n=n/10;
	}
	
	
	return 0;
}

b.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值