当前位置:网站首页>Experiment 2
Experiment 2
2020-11-09 23:53:00 【Ey】
The first question is
Enter month day year (mm/dd/yyyy), Date of output (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;
}
The second question is
Format the product information entered by users
#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;
}
Third question
Decompose user input ISBN Information
#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;
}
Fourth question
With (XXX)XXX-XXXX Enter the phone number in the format of , With XXX.XXX.XXXX Format output
#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;
}
Question seven
Enter two digits , Print the number in reverse order
#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;
}
The eighth question
Input integer , Output this number in octal
#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;
}
Question 9 (1)
Input in three parts UPC Pre code 11 position , Calculate check bits
#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;
}
Question 9 (2)
One time input UPC Pre code 11 position , Calculate the check bits
#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;
}
Question 10
Input EAN Pre code 12 position , Calculate the check code
#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]所创,转载请带上原文链接,感谢
边栏推荐
- 接缝雕刻算法:一种看似不可能的图像大小调整方法
- CUDA_常量内存
- nodejs篇-手写koa中间件
- Top 5 Chinese cloud manufacturers in 2018: Alibaba cloud, Tencent cloud, AWS, telecom, Unicom
- What is the SRM system? SRM supplier management system functions
- 手把手教你使用容器服务 TKE 集群审计排查问题
- Interviewer: what are cache penetration, cache avalanche and cache breakdown?
- 商品后台系统优化
- C + + game development
- So what should investors do with the current market? Now a new investment outlet is coming!
猜你喜欢
Unity使用transform.Rotate进行三维旋转角度出现偏差
异常:Invalid or unexpected token
编码风格:Mvc模式下SSM环境,代码分层管理
IP address SSL certificate
Exhibition cloud technology interpretation | in the face of emergencies, how does app do a good job in crash analysis and performance monitoring?
One image can hold 16x16 words! ——Transformers for large scale image scaling recognition (a brief review of ICLR 2021 papers)
编码风格:Mvc模式下SSM环境,代码分层管理
day85:luffy:购物车根据有效期不同切换价格&购物车删除操作&价格结算&订单页面前戏
价值超10亿美元的直播系统架构图是什么样子的?
JMeter的简单使用
随机推荐
公网IP地址和SSL证书可以提升SEO吗?
ES6, ES7, es8 Learning Guide
CRM系统能帮助企业做哪些事?
C / C + + Programming Notes: C language development tank war! In memory of our lost little overlord game
Using tail as time series to identify whales
No space left on device
Come and learn! Development Guide for personalized recommendation system (with internet disk link)
CUDA_ Global memory and access optimization
快来学习!个性化推荐系统开发指南(附网盘链接)
做个别人家的网页
What can CRM system help enterprises do?
iNeuOS工业互联平台,WEB组态(iNeuView)增加工程视图导入、导出功能,及优化和修复,发布:v3.2.1版本
ES6、ES7、ES8学习指南
Common concepts and points for attention of CUDA
接缝雕刻算法:一种看似不可能的图像大小调整方法
Problems of input and button (GAP / unequal height / misalignment) and Solutions
Error running app: default activity not found solution
One image can hold 16x16 words! ——Transformers for large scale image scaling recognition (a brief review of ICLR 2021 papers)
2018中国云厂商TOP5:阿里云、腾讯云、AWS、电信、联通 ...
Promote China manufacturing upgrade, 3D visualization of production line in automobile assembly workshop