当前位置 :
大哥你看这两个程序应该怎么写Supposethatwehaveafile,profit.in,containingaseriesoflines,eachgivingtheproductcode,quantity,costandpriceofitemssoldinasmallstoreduringaonedayperiod.Forexample,101542.052.951051
1人问答
八字精批流年运程八字合婚八字起名
问题描述:

大哥你看这两个程序应该怎么写

Supposethatwehaveafile,profit.in,containingaseriesoflines,eachgivingtheproductcode,quantity,costandpriceofitemssoldinasmallstoreduringaonedayperiod.For

example,101542.052.95

105121.591.98

2301210.870.99

167112.673.98

Theprofitforanitemisquantitytimesthedifferencebetweenpriceandcost.

Writeaprogram,profit.c,whichpromptstheuserforanproductcodethenreadsthrough

thefiletofindtheprofitforthatitem.Theprogramthenprintstheproductcodealong

withtheprofit.Iftheproductcodeisnotpresentinthefilethentheprogramshouldprinta

messagesayingso.

Forexample,iftheinputfileconsistsofthe4linesshownaboveandtheuserentersaproduct

codewhichispresentinthefilethentheprogramoutputmustlooklike:

Enteraproductcode:230

Profitforproduct230is14.52

Enteraproductcode:231

product231isnotfound

就是说读入这个文件中数字来计算但是原来学的都是自己自动比较计算什么的这个user自己输入然后读入文件内容计算应该怎么写好呢

2Writeaprogram,powers.c,whichusesafunction,integerpower,asfollows:

Step1:Readinafloatxandanintegernfromtheuser.

Step2:Callthefunctionintegerpowerwhichcomputesandreturnsx

n.Therearethreecasestoconsider:1)whennispositive,multiplyxbyitselfntimes;(2)whennisnegative,first

multiplyxbyitself|n|times–theresultisthen1.0overtheproduct;andwhenn=0

theresultis1.0.Donotusethefunctionpowfromthemathlibrary

这个题是不是一开始的时候intintergerpower(intn);floatpowers(floatx)只能这么写啊不能两个在一个里面写然后后面的程序用for语句?

毛经中回答:
  第一道题:   #include   #include   intmain(void)   {   FILE*fp;   intid;   intcode,quantity;   floatcost,price;   intstatus,found;   while(1)   {   printf("Enteraproductcode:");   scanf("%d",&id);   if( id==-1)break;   if((fp=fopen("d:profit.in","r"))==NULL)   {   printf("openprofit.infailed");   continue;   }   fseek(fp,0,0);   found=0;   while(1)   {   status=fscanf(fp,"%d%d%f%f",&code,&quantity,&cost,&price);   if(status==EOF||status==0)break;   if(code==id)   {   found=1;   break;   }   }   if(found==1)   {   printf("Profitforproduct%dis%.2fn",id,quantity*(price-cost));   }   else   {   printf("product%disnotfoundn",id);   }   fclose(fp);   }   return0;   }   你的文件存为profit.in,路径你自己改if((fp=fopen("d:profit.in","r"))==NULL)   注意要使用转义字符.   第二题:   #include   #include   doubleintegerpower(doublex,intn)   {   inti;   doublexn;   if(n>0)   {   for(xn=1,i=0;i
八字精批 八字合婚 八字起名 八字财运 2024运势 测终身运 姓名详批 结婚吉日
已出生未出生
最新更新
PC端 | 移动端 | mip端
字典翻译(zidianfy.com)汇总了汉语字典,新华字典,成语字典,组词,词语,在线查字典,中文字典,英汉字典,在线字典,康熙字典等等,是学生查询学习资料的好帮手,是老师教学的好助手。
声明:本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
电话:  邮箱:
Copyright©2009-2021 字典翻译 zidianfy.com 版权所有 闽ICP备2022014709号-7
lyric 頭條新聞
复制重新加载
原创不易,您的支持将成为鼓励我的动力
《大哥你看这两个程序应该怎么写Supposethatwehaveafile,profit.in,containingaseriesoflines,eachgivingtheproductcode,quantity,costandpriceofitemssoldinasmallstoreduringaonedayperiod.Forexample,101542.052.951051|其它问答-字典翻译问答网》
1、付费复制方式
支付宝付费后即可复制当前文章
限时特价:5.99元
原价:20元
打开支付页
2、微信付费复制方式
微信扫码付费后即可复制当前文章
限时特价:5.99元
原价:20元