您的位置首页百科问答

基础编程题

基础编程题

的有关信息介绍如下:

基础编程题

LZ想要的是这种答案吧。。。。//-------------------------------第一题#include #include "e:\myc\zylib\zylib.h"STRING GetString(STRING prompt);double GetReal(STRING prompt);int main(){ double bookprice; STRING bookname; bookname=GetString("请输入字符串:"); bookprice=GetReal("请输入实数:"); printf("字符串为:%s\n",bookname); printf("实数为:%.2f\n",bookprice);}STRING GetString(STRING prompt){ STRING name; printf("%s",prompt); name=GetStringFromKeyboard(); return name;}double GetReal(STRING prompt){ double price; printf("%s",prompt); price=GetRealFromKeyboard(); return price;}//-------------------------------------第二题#include #include "e:\myc\zylib\zylib.h"BOOL IsPrime(int n);int main(){ int n; printf("请输入一个整数:"); scanf("%d",&n); if(n>2) if(IsPrime(n))printf("%d是素数\n",n); else printf("%d不是素数\n",n); else printf("数据非法\n"); return 0;}BOOL IsPrime(int n){ int i; for(i=2;i#define TRUE 1 int gcd(int x,int y);int main(){int m,n,max;printf("请输入两个正整数:");scanf("%d %d",&m,&n);max=gcd(m,n);printf("最大公约数为:%d\n",max);return 0;}int gcd(int x,int y){int r;while(TRUE){ r=x%y;if(r==0)break;x=y;y=r;}return y;}//--------------------------------第四题#include #include "e:\myc\zylib\zylib.h"typedef enum{sun,mon,tue,thi,wen,fri,sat}WEEKDAY;//定义枚举类型int GetInteger(STRING prompt);//输入一下整数int Count(int year,int month);//计算某年某月之前到2007年1月1日的天数BOOL IsLeapYear(int n);//判断某年是否是闰年int month_day(int year,int month);//计算某个月的天数void print(int year,int month,int total);//打印某年某月的日历void print1(WEEKDAY weekday);//打印某月的第1天int main(){ int year,month,total; year=GetInteger("please input year:"); if(year<2007) PrintErrorMessage(FALSE,"年份小于2007,错误\n"); month=GetInteger("please input month:"); total=Count(year,month); print(year,month,total);}int GetInteger(STRING prompt){ int t; printf("%s",prompt); t=GetIntegerFromKeyboard(); return t;}int Count(int year,int month){ int s,i; s=0; for(i=2007;i