资源描述:
《请写出以下序的运行结果,并说明其功能.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、1.请写出以下程序的运行结果,并说明其功能a)#includeintmain(void){intnum1,denom1,num2,denom2,result_num,result_denom;printf("Enterfirstfraction:");scanf("%d/%d",&num1,&denom1);printf("Entersecondfraction:");scanf("%d/%d",&num2,&denom2);result_num=num1*denom2+num2*denom1;result_denom=denom1*den
2、om2;printf("Thesumis%d/%d",result_num,result_denom);return0;}b)#includedoubleaverage(doublea,doubleb){return(a+b)/2;}intmain(void){doublex,y,z;printf("Enterthreenumbers:");scanf("%lf%lf%lf",&x,&y,&z);printf("Averageof%gand%g:%g",x,y,average(x,y));printf("Averageof%gand
3、%g:%g",y,z,average(y,z));printf("Averageof%gand%g:%g",x,z,average(x,z));return0;}c)#include#defineFREEZING_PT32.0f#defineSCALE_FACTOR(5.0f/9.0f)intmain(void){floatfahrenheit,celsius;printf("EnterFahrenheittemperature:");scanf("%f",&fahrenheit);celsius=(fahrenheit-FREEZ
4、ING_PT)*SCALE_FACTOR;printf("Celsiusequivalent:%.1f",celsius);return0;}a)#includevoidprint_count(intn){printf("Tminus%dandcounting",n);}intmain(void){inti;for(i=10;i>0;--i)print_count(i);return0;}b)#include#include#includestructcity_info{ch
5、ar*city;intmiles;};intcompare_cities(constvoid*key_ptr,constvoid*element_ptr);intmain(void){charcity_name[81];structcity_info*ptr;conststructcity_infomileage[]={{"Berlin",3965},{"BuenosAires",5297},{"Cairo",5602},{"Calcutta",7918},{"CapeTown",7764},{"Caracas",2132},{"Chicago",713},
6、{"HongKong",8054},{"Honolulu",4964},{"Istanbul",4975},{"Lisbon",3364},{"London",3458},{"LosAngeles",2451},{"Manila",8498},{"MexicoCity",2094},{"Montreal",320},{"Moscow",4665},{"Paris",3624},{"RiodeJaneiro",4817},{"Rome",4281},{"SanFrancisco",2571},{"Shanghai",7371},{"Stockholm",392
7、4},{"Sydney",9933},{"Tokyo",6740},{"Warsaw",4344},{"Washington",205}};printf("Entercityname:");scanf("%80[^]",city_name);ptr=bsearch(city_name,mileage,sizeof(mileage)/sizeof(mileage[0]),sizeof(mileage[0]),compare_cities);if(ptr!=NULL)printf("%sis%dmilesfromNewYorkCity.",city_na
8、me,ptr->miles);elseprintf(