C语言程序设计现代方法习题第三章

第一题

#include <stdio.h>
#include<string>)
int main()
{
	int m, d, y;
	printf("Enter a data(mm/dd/yy):");
	scanf("%d/%d/%d", &m, &d, &y);
	printf("You entered the data %d%.2d%.2d\n", y, m, d);
	system("pause");
	return 0;
}

第二题

#include <stdio.h>
#include<string>)
int main()
{
	int item, day, month, year;
	float price;
	printf("Enter item number: ");
	scanf_s("%d", &item);
	printf("Enter unit price: ");
	scanf_s("%f", &price);
	printf("Enter purchase date(mm/dd/yy): ");
	scanf_s("%d / %d / %d", &month, &day, &year);
	printf("Item\tUnit\tPurchase\n\tPrice\tDate\n%d\t$ %-f\t%d/%d/%d",item,price,month,day,year);
	system("pause");
	return 0;
}

第三题

#include <stdio.h>
#include<string>)
int main()
{
	int a, b, c, d, e;
	printf("Enter ISBN: ");
	scanf_s("%d-%d-%d-%d-%d", &a, &b, &c, &d, &e);
	printf("DS1 prefix: %d\n", a);
	printf("Group idemtifier: %d\n", b);
	printf("Publisher code: %d\n", c);
	printf("Item number: %d\n", d);
	printf("Check digit: %d\n", e);
	system("pause");
	return 0;
}

第四题

#include <stdio.h>
#include<string>)
int main(void)
{
	int a=0, b=0, c=0;
	printf("Enter phone number [(xxx)xxx-xxxx]: ");
	scanf_s("(%d) %d-%d", &a,&b,&c);
	printf("You entered %d.%d.%d", a,b,c);
	system("pause");
	return 0;
}

第五题

#include <stdio.h>
#include<string>)
int main(void)
{
	int a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4;
	printf("Enter the numbers from 1 to 16 in any order: ");
	scanf_s("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&c1,&c2,&c3,&c4,&d1,&d2,&d3,&d4);
	printf("%d\t%d\t%d\t%d\n", a1, a2, a3, a4);
	printf("%d\t%d\t%d\t%d\n", b1, b2, b3, b4);
	printf("%d\t%d\t%d\t%d\n", c1, c2, c3, c4);
	printf("%d\t%d\t%d\t%d\n", d1, d2, d3, d4);
	printf("Row sums: %d %d %d %d\n",a1 + a2 + a3 + a4, b1 + b2 + b3 + b4, c1 + c2 + c3 + c4, d1 + d2 + d3 + d4);
	printf("Column sums: %d %d %d %d\n", a1 + c1 + b1 + d1, a2 + b2 + c2 + d2, a3 + b3 + c3 + d3, a4 + b4 + c4 + d4);
	printf("Diagonal sums:%d %d\n", a1 + b2 + c3 + d4, d1 + c2 + b3 + a4);
	system("pause");
	return 0;
}

第六题

#include <stdio.h>
#include<string>)
int main(void)
{
	int a1, a2, b1, b2, c1, c2;
	printf("Enter two fractions separated by a plus sign:");
	scanf_s("%d/%d+%d/%d", &a1, &a2, &b1, &b2);
	c1 = a1*b2 + b1*a2;
	c2 = a2*b2;
	printf("The sum is: %d/%d\n", c1, c2);
	system("pause");
	return 0;
}

题目如下
在这里插入图片描述

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值