c语言问题,急求解答!!!

问题1:WriteaCprogramthatprintsoutalldifferentpossibilitiesofobtaining£1(1pound)us... 问题1:
Write a C program that prints out all different possibilities of obtaining £1(1 pound)
using coins of values 2 pence, 5 pence, and 10 pence. Indicate how many
possibilities have been found. The output of your program may look like:
£1 = 50 x 2p
£1 = 45 x 2p + 2 x 5p
£1 = 40 x 2p + 4 x 5p

In total, there are 66 possibilities to make £1.
Hint: You may use loops to generate the number of coins n2, n5, and n10 of value 2,
5, and 10 pence respectively and use the formula £1=100p=2*n2+5*n5+10*n10.

问题2:
Write a program that takes as input a sequence of scores (integer numbers between 0 and 20)
and finds the followings:
1. The highest score for that sequence as well as the number of times that maximum has
been attained.
2. The lowest score for that sequence as well as the number of times that minimum has
been attained.
We assume the number of scores is not known in advance and that the program will stop when
we enter the score -1. An execution of the program may look like the following:
Give a score (-1 to end): 12
Give a score (-1 to end): 8
Give a score (-1 to end): 13
Give a score (-1 to end): 7
Give a score (-1 to end): 11
Give a score (-1 to end): 12
Give a score (-1 to end): 7
Give a score (-1 to end): 9
Give a score (-1 to end): -1
Highest score: 13 attained 1 times
Lowest score: 7 attained 2 times
Hint: Use a while loop to read in the scores and keep track of the minimum and maximum
scores as well as their number of occurrences.
展开
 我来答
百度网友3fcc8cb
2009-10-27 · 超过14用户采纳过TA的回答
知道答主
回答量:49
采纳率:0%
帮助的人:36.3万
展开全部
哎,写了一下午,全部正确
第一题:
#include<stdio.h>
void main()
{
int i,j,k,num=0;
for(k=0;k<=10;k++)
for(j=0;j<=20;j++)
for(i=0;i<=50;i++)
if(2*i+5*j+10*k==100)
{
printf("£1 =100p=2*%d+5*%d+10*%d\n",i,j,k);
num++;
}
printf("In total, there are %d possibilities to make £1",num);
}

第二题:
#include<stdio.h>
#include<string.h>
void main()
{
int a[15],i,max,min,nums=1,numb=1; /*nums最小数出现次数,numb最大数出现次数*/
printf("please input 15 scores (end with -1,less then 15 number intotal.\n shoulde be integer numbers between 0 and 20)\n");
for(i=0;i<=14;i++)
scanf("%d",&a[i]);
for(i=1,max=min=a[0];a[i]!=-1;i++)
{if(a[i]>max)
{max=a[i];numb=1;
}
else if(a[i]==max)numb++;
if(a[i]<min)
{min=a[i];nums=1;
}
else if(a[i]==min)nums++;
}
printf("Highest score: %d attained %d times\nLowest score: %d attained %d times\n",max,numb,min,nums);
}
孟徳
2009-10-27 · TA获得超过421个赞
知道小有建树答主
回答量:500
采纳率:0%
帮助的人:223万
展开全部
第一题有人问过有人答过,你自己翻翻
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式