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

来源:百度知道 编辑:UC知道 时间:2024/06/22 02:07:22
问题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

哎,写了一下午,全部正确
第一题:
#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("Highe