当前位置:网站首页>实验2
实验2
2020-11-09 23:53:00 【Ey】
第一题
输入月日年(mm/dd/yyyy),输出年月日(yyyy/mm/dd)
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter a date (mm/dd/yyyy):");
scanf("%d/%d/%d",&a,&b,&c);
printf("You Enter the date %d%.2d%.2d",c,a,b);
return 0;
}
第二题
对用户录入的产品信息格式化
#include<stdio.h>
int main()
{
int number,a,b,c;
float price;
printf("Enter item number:");
scanf("%d",&number);
printf("Enter unit price: ");
scanf("%f",&price);
printf("Enter purchase date(mm/dd/yy):");
scanf("%d/%d/%d",&a,&b,&c);
printf("Item\tUnit Price\tPurchase date\n");
printf("%-d\t$%4.2f\t\t%-.2d/%.2d/%d",number,price,a,b,c);
return 0;
}
第三题
分解用户输入的ISBN信息
#include<stdio.h>
int main()
{
int a,b,c,d,e;
printf("Enter ISBN: ");
scanf("%d-%d-%d-%d-%d",&a,&b,&c,&d,&e);
printf("GSI Prefix: %d\n",a);
printf("Group identifier: %d\n",b);
printf("Publisher code: %.3d\n",c);
printf("Item number: %.5d\n",d);
printf("Check digit: %d\n",e);
return 0;
}
第四题
以(XXX)XXX-XXXX的格式输入电话号码,以XXX.XXX.XXXX的格式输出
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter phone number[(xxx) xxx-xxxx]: ");
scanf("(%d) %d-%d",&a,&b,&c);
printf("You entered %.3d.%.3d.%.4d",a,b,c);
return 0;
}
第七题
输入两位数,按数位的逆序打印出这个数
#include<stdio.h>
int main()
{
int number,a,b;
printf("Enter a two-digit number:");
scanf("%d",&number);
a = number/10;
b = number%10;
printf("The reverse is %d%d",b,a);
return 0;
}
第八题
输入整数,按八进制输出这个数
#include<stdio.h>
int main()
{
int number;
printf("Enter a number between 0 and 32767:");
scanf("%d",&number);
printf("In octal,your number is ");
printf("%.5o",number);
return 0;
}
第九题(1)
分三部分输入UPC码前11位,计算校验位
#include<stdio.h>
int main()
{
int f,a1,a2,a3,a4,a5,b1,b2,b3,b4,b5,n;
printf("Enter the first (single) digit:");
scanf("%d",&f);
printf("Enter first group of five digits:");
scanf("%1d%1d%1d%1d%1d",&a1,&a2,&a3,&a4,&a5);
printf("Enter second group of five digits:");
scanf("%1d%1d%1d%1d%1d",&b1,&b2,&b3,&b4,&b5);
n=9-(((f+a2+a4+b1+b3+b5)*3+(a1+a3+a5+b2+b4)-1)%10);
printf("Check digits:%d",n);
return 0;
}
第九题(2)
一次性输入UPC码前11位,计算检验位
#include<stdio.h>
int main()
{
int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,n;
printf("Enter the first 11 digits of UPC:");
scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d",&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10,&a11);
n=9-((((a1+a3+a5+a7+a9+a11)*3)+(a2+a4+a6+a8+a10)-1)%10);
printf("Check digit:%d",n);
return 0;
}
第十题
输入EAN码前12位,计算校验码
#include<stdio.h>
int main()
{
int a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,n;
printf("Enter the first 12 digits of EAN:");
scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d",&a1,&a2,&a3,&a4,&a5,&a6,&a7,&a8,&a9,&a10,&a11,&a12);
n=9-((((a2+a4+a6+a8+a10+a12)*3)+(a1+a3+a5+a7+a9+a11)-1)%10);
printf("Check digit:%d",n);
return 0;
}
版权声明
本文为[Ey]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4777478/blog/4710363
边栏推荐
猜你喜欢
嘉宾专访|2020 PostgreSQL亚洲大会阿里云数据库专场:王健
[leetcode] 92 integer inversion
Come and learn! Development Guide for personalized recommendation system (with internet disk link)
Exception: invalid or unexpected token
Interviewer: what are cache penetration, cache avalanche and cache breakdown?
Application of V7 version of lvgl Library
Brief analysis of LinkedList source code
Functional guide for temporary users and novices of PL / SQL developer
白山云科技入选2020中国互联网企业百强
Apache Hadoop的重要组成
随机推荐
白山云科技入选2020中国互联网企业百强
jt-京淘项目
利用尾巴作为时间序列进行处理来识别鲸鱼
CUDA常用概念及注意点
DB-Engines 11月数据库排名:PostgreSQL坐稳同期涨幅榜冠军宝座
lvgl 库 V7版本相关应用
没有磁盘空间 No space left on device
Incomplete Polyfill of proxy
初级工程师如何在职场生存
获取List集合对象中某一列属性值
crm系统的成本一般是多少?
CUDA_ Register and local memory
Gets the property value of a column in the list collection object
Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
Baishan cloud technology is selected as the top 100 Internet enterprises in China in 2020
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
当我们开发一个接口时需要注意些什么
Can't find other people's problem to solve
函数计算进阶-IP查询工具开发
Unity使用transform.Rotate进行三维旋转角度出现偏差