第一题
#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;
}
题目如下