C语言如何控制输出11位手机号码,不能多不能少,能控制第一位数字是1就更好了,录入信息用的,大学C语言课设作业,急求!!!弄不完回不了家😭
2条回答 默认 最新
- 浪客 2021-07-01 22:02关注
#include <iostream> using namespace std; int getTel(char *tel) { char ch; int n = 0; while (n != 11) { cin >> ch; if (ch >= '0' && ch <= '9') { if (n == 0 && ch != '1') { cout << "手机号第一位必须是1" << endl; fflush(stdin); continue; } *(tel + n) = ch; } else { cout << "手机号必须是数字" << endl; fflush(stdin); n = 0; continue; } n++; } *(tel + n) = '\0'; return n; } int main() { char tel[12] = {0}; int n; while (1) { n = getTel(tel); if (n == 11) { cout << tel << endl; break; } else cout << "输入错误,请重新输入!\n" << endl; } return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用
悬赏问题
- ¥15 yolov8边框坐标
- ¥15 matlab中使用gurobi时报错
- ¥15 WPF 大屏看板表格背景图片设置
- ¥15 这个主板怎么能扩出一两个sata口
- ¥15 不是,这到底错哪儿了😭
- ¥15 2020长安杯与连接网探
- ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
- ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
- ¥16 mybatis的代理对象无法通过@Autowired装填
- ¥15 可见光定位matlab仿真