问题 1009: [编程入门]数字的处理与判断

https://www.dotcpp.com/oj/problem1009.htmlhttps://www.dotcpp.com/oj/problem1009.html
https://www.dotcpp.com/oj/problem1009.html

思路;1.记录位数
2.输出每一位数(1.可用数组,再用strlen函数 2.可用除法和求余)
3.逆序输出原数(1.用数组 .)

一代(特别注意输出的字符类型)

#include<stdio.h>
#include<string.h>
int  main()
{
  int i,n;
  char str[5];//记录原数
  scanf("%s",&str);
  n=strlen(str);//n记录长度
  printf("%d\n",n);
  for(i=0;i<n;i++) printf("%c ",str[i]);
     printf("\n");
   for(i=n-1;i>=0;i--) printf("%c",str[i]);//逆序输出原数
   printf("\n");
  return 0;

}

二代

#include <stdio.h>
int main()
{
    int i,count=0,x[5];             //count统计位数,x[5]储存数字
    for (i=0;i<5;i++)
    {
        int temp=0;
        temp=getchar();             //temp临时储存数字字符的ASCII码
        if (temp==10) break;      //输入换行\n后跳出for循环
        count++;
        x[i]=temp-48;               //字符0的ASCII码是48
    }
    printf("%d\n",count);
    for (i=0;i<=count-2;i++) printf("%d ",x[i]);
    printf("%d\n",x[i]);
    for (i=count-1;i>=0;i--) printf("%d",x[i]);
    return 0;
}```

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值