关于C语言的一道试题求助高手

Question1-20marksWriteaCprogramthatprintsoutallofthedifferentwaysofobtaining1(1pound)... Question 1 - 20 marks

Write a C program that prints out all of the different ways of obtaining 1 (1 pound) using coins of values 1
pence, 2 pence, 5 pence. Indicate how many possibilities have been found. The output of your program
should look like:
1 = 100 x 1p
1 = 90 x 1p + 5 x 2p
1 = 80 x 1p + 5 x 2p+2x5p....
Your C program should also calculate the number of possible ways of making 1 using the available coins.
Question 2 - 30 marks
Write a C function using pointer(s) called PFunc that take as input an m x n matrix “A” and an n x q matrix
“B” as well as a C program to test this function. Your program should:
1.
represent the matrices as two two-dimensional arrays
2.
allow the user to specify the size of array A and B, i.e., m, n, q at execution time
3.
use malloc to allocate memory space for the array
4.
calculate and display the resulting matrix AxB
5.
check in your function if AxB is a symmetric matrix and also display this information
6.
your function should calculate and display the largest value in the array (AxB).
You should design your own input and output format for this program.
Question 3 - 50 marks
A ferry has a seating capacity of 30 arranged in 10 rows (1 to 10) of three seats: A, B and C (i.e. the seat
identification labels are 1A, 1B, 1C, etc.). The ferry makes one trip a day. Write a seating reservation
program for the ferry in C with the following features:
展开
 我来答
金色潜鸟
2013-07-24 · TA获得超过3.2万个赞
知道大有可为答主
回答量:1.3万
采纳率:89%
帮助的人:6692万
展开全部
题目太多。
第一题简单。用循环语句加判断就可以了。
给你第2题答案。命令行 带 3 个参数,例如 a.exe 3 2 3
#include<stdio.h>
#include <stdlib.h>
#define DEBUG 1
void PFunc(int *a, int *b, int a_row, int a_col, int b_col)
{
int i,j,b_row;
static int tmp;
b_row = a_col;
printf("Please input int matrix a[%d][%d] 1 2 3 4 5 6\n",a_row,a_col);
for (j=0;j<a_row;j++) for (i=0;i<a_col;i++){
scanf("%d",&tmp);
a[j*a_col+i] = tmp;
}
printf("Please input int matrix b[%d][%d] 1 2 3 4 5 6\n",b_row,b_col);
for (j=0;j<b_row;j++)
for (i=0;i<b_col;i++){
scanf("%d",&tmp);
b[j*b_col+i] = tmp;
}
}

void show_array(int *a, int row,int col);
void matrix2(int *a,int *b, int *c, int a_row, int b_col, int b_row)
{
int i,j,k;
int a_col,c_row,c_col;
a_col=b_row; c_row=a_row; c_col=b_col;
for(j=0;j<c_row;j++){
for(i=0;i<c_col;i++){
c[j*c_col+i]=0;
for(k=0;k<a_col;k++) c[j*c_col+i]+= a[j*a_col+k] * b[k*b_col+i];
};
};
}

main(int argc, char *argv[])
{
int i,j,k,tmp;
int a_row,a_col,b_row,b_col,c_row,c_col;
int *a,*b,*c;
// int m,n,q; //m=a_row; n=a_col,b_row; q=b_col
if (argc < 4){
printf("Usage:%s a_row a_col b_row\n",argv[0]);
printf("For example:%s 3 2 3\n",argv[0]);
return 0;
}
sscanf(argv[1],"%d",&a_row);
sscanf(argv[2],"%d",&a_col);
sscanf(argv[3],"%d",&b_col);
b_row = a_col;
c_row = a_row;
c_col = b_col;
a = (int *) malloc(sizeof(int *) * a_row * a_col);
b = (int *) malloc(sizeof(int *) * b_row * b_col);
c = (int *) malloc(sizeof(int *) * c_row * c_col);
if (!c) { printf("no enought memory for alloc\n");return 0; }
PFunc(a,b, a_row, a_col, b_col);

printf("A[%d][%d]:\n",a_row,a_col);
show_array(a,a_row,a_col);
printf("B[%d][%d]:\n",b_row,b_col);
show_array(b,b_row,b_col);
matrix2( a,b,c, a_row, b_col, b_row);
printf("C[%d][%d]:\n",c_row,c_col);
show_array(c,c_row,c_col);
free(a);free(b);free(c);
return 0;
}

void show_array(int *a, int row,int col)
{
int i,j;
for (j=0;j<row;j++){
for (i=0;i<col;i++) printf("%d ",a[j*col+i]);
printf("\n");
}
printf("--------------------\n");
}
快情签10
2013-07-25 · TA获得超过293个赞
知道小有建树答主
回答量:197
采纳率:0%
帮助的人:193万
展开全部
/* Question A */
void main()
{
  int i,j,k;
  for (i=0;i<=100;i++)
    for (j=0;j<=50;j++)
      for (k=0;k<=20;k++)
        if (i*1+j*2+k*5==100)  printf("1=%d x 1p + %d x 2p+ %d x 5p",i,j,k);
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
beiwjk
2013-07-24 · 超过20用户采纳过TA的回答
知道答主
回答量:155
采纳率:0%
帮助的人:42万
展开全部

/* xjsincxkjfvksdhf  /*

a

}

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式