3.王道C-Review-选择、循环

Description
输入一个整型数,判断是否是对称数,如果是,输出yes,否则输出no,不用考虑这个整型数过大,int类型存不下,不用考虑负值;
例如 12321是对称数,输出yes,124421是对称数,输出yes,1231不是对称数,输出no

Input
一个整型数

Output
输出是yes,或者no

Sample Input 1

12321

Sample Output 1

yes

Sample Input 2

1231

Sample Output 2

no

Anser:

#include <stdio.h>
int main()
{
	int a,b,c,tmp;
  	scanf("%d",&a);
  	b = 0;
  	c = a;
  
  	while(a){
    	tmp = a % 10;
      	b = b*10 + tmp;
      	a = a / 10;
    }
  
  	if(b == c){
    	printf("yes \n");
    } else {
    	printf("no \n");
    }
  
  	return 0;
}

Description
利用while或者for循环计算n!的值。
提示:n!=123…*n

Input
一个正整数n,1≤n≤10。

Output
n!的值。

Sample Input 1

2

Sample Output 1

2

Sample Input 2

5

Sample Output 2

120

Anser:

#include <stdio.h>
int main()
{
	int i,n,total;
  	scanf("%d",&n);
	total = 1;
  
  	for(i = 1; i <= n; i++){
    	total *= i;
    }
  
  	printf("%d",total);
  	return 0;
}

Description
某人想将手中的一张面值100元的人民币换成10元、5元、2元和1元面值的票子。要求换正好40张,且每种票子至少一张。问:有几种换法?

Input
无输入

Output
一个数,表示共有多少种换法

Sample Input 1

无输入

Sample Output 1

不能告知,因为只有一个数,偷偷告诉你小于100

Anser:

#include <stdio.h>
int main()
{
	int i,j,m,n,t;
  
  	t = 0;
  	
  	for(i = 1; i <= 10; i++){
    	for(j = 1; j <= 20; j++){
        	for(m = 1; m <= 37; m++){
            	for(n = 1; n <37; n++) {
                	if(i+j+m+n==40 && 10*i+5*j+2*m+n==100){
                  		t += 1;  	
                    }
                }
            }
        }
    }
  	printf("%d",t);
}
  • 9
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值