从键盘输入正整数n和0~9范围内的一个数字m,判断m是否存在于n中,并进行一系列操作。

程序功能:从键盘输入正整数n和0~9范围内的一个数字m,判断m是否存在于n中,如不存在则输出“m不存在于n中”字样(m,n以具体输入的值代替);如存在则删除n中的数字m,构成一个新数k(高位为原高位,低位为原低位),并求出原数n是新数k的倍数(保持2位小数),然后依次输出新数k和倍数,中间以一个逗号分隔。

样例输入1:
12345 2
样例输出1:
1345,9.18
样例说明:输入n为12345,m为2;删除2后的新数k为1345,n是k的9.18倍。
样例输入2:
12045 0
样例输出2:
1245,9.67
样例说明:输入n为12045,m为0;删除0后的新数k为1245,n是k的9.67倍。
样例输入2:
12045 0
样例输出2:
1245,9.67
样例说明:输入n为12045,m为0;删除0后的新数k为1245,n是k的9.67倍。

#include <stdio.h>
#include<string.h>
int main()
{
    char s[10];
    int a,i=0,y,y1,y2,flag=0,b[10];
//    gets(s);
       scanf("%s",s);
    y=strlen(s);
    y1=atoi(s);
    scanf("%d",&a);
    for(i=0;i<y;i++)
        if(s[i]==a+'0')
        {
            flag=1;
            break;}
if(flag==0)       printf("%d不存在于%s中\n",a,s);
else {
    do{
    s[i]=s[i+1];
    i++;
} while(i!=y);
    y2=atoi(s);
printf("%s,%.2f",s,y1*1.0/y2);}
      return 0;
}
#include <stdio.h>
//判该位是否存在
int isExist(int n,int m)
{
     while(n)
     {
         if(m==n%10)
             return 1;
         n/=10;
     }
     return 0;
}
int main()
{
    int n,nbk,m,k=0,t,p=1;
    scanf("%d%d",&n,&m);
    nbk=n;
    if(isExist(n,m)){
       while(n){
        t=n%10;
        if(t!=m){
        k+=t*p;
        p*=10;
        }
        n/=10;
       }
       printf("%d,%.2f\n",k,nbk*1.0/k);
    }
    else
      printf("%d不存在于%d中\n",m,n);
    return 0;
}	
  • 7
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值