Question1: Matrix operations using array and function.
Write a complete C program to perform Matrix operations such as Addition, Subtraction, Multiplication and Transpose according to the user’s choice. Define functions to perform these various operations and call them from the main function whenever needed. The program should display the following menu to the user for them to select one of the five options listed.
------------------
MAIN MENU
------------------
1.MATRIX ADDITION
2.MATRIX SUBTRACTION
3.MATRIX MLTIPLICATION
4.MATRIX TRANSPOSE
5.TO EXIT
---------------------------
Please enter your option <1/2/3/4/5>:
The program should ask the elements of the input matrix or matrices from the user once the required operation is selected and also should check whether the required operation can be carried out or not based on the input data. The program should produce a neat output showing both the input and the resultant matrix in matrix form. The program should not be terminated until the user selects the option number 5 (TO EXIT).
#include "stdafx.h"
#include <stdio.h>
int main()
{
int add,sub,mul,tran,opt;
printf("---------\n");
printf("MAIN MENU\n");
printf("---------\n");
printf("1-MATRIX ADDITION\n");
printf("2-MATRIX SUBTRACTION\n");
printf("3-MATRIX MULTIPLICATION\n");
printf("4-MATRIX TRANPOSE\n");
printf("5-EXIT\n");
printf("-------------------\n");
printf("Please enter your option <1/2/3/4/5>:\n");
scanf("%d",&opt);
switch(opt);
{
case 1:这里开始完全不懂怎样写!
while(opt == 5);
{
printf("---------\n");
printf("MAIN MENU\n");
printf("---------\n");
printf("1-MATRIX ADDITION\n");
printf("2-MATRIX SUBTRACTION\n");
printf("3-MATRIX MULTIPLICATION\n");
printf("4-MATRIX TRANPOSE\n");
printf("5-EXIT\n");
printf("-------------------\n");
printf("Please enter your option <1/2/3/4/5>:\n");
scanf("%d",&opt);
}
}
原帖由 aiklone1314 于 2009-9-6 11:43 PM 发表
我到这里就不会了:
[quote]#include "stdafx.h"
#include <stdio.h>
int main()
{
int add,sub,mul,tran,opt;
printf("---------\n");
printf("MAIN MENU\n");
printf("---------\n");
printf("1-MATRIX ADDITION\n");
printf("2-MATRIX SUBTRACTION\n");
printf("3-MATRIX MULTIPLICATION\n");
printf("4-MATRIX TRANPOSE\n");
printf("5-EXIT\n");
printf("-------------------\n");
printf("Please enter your option <1/2/3/4/5>:\n");
scanf("%d",&opt);
switch(opt);
{
case 1:这里开始完全不懂怎样写!
while(opt == 5);
{
printf("---------\n");
printf("MAIN MENU\n");
printf("---------\n");
printf("1-MATRIX ADDITION\n");
printf("2-MATRIX SUBTRACTION\n");
printf("3-MATRIX MULTIPLICATION\n");
printf("4-MATRIX TRANPOSE\n");
printf("5-EXIT\n");
printf("-------------------\n");
printf("Please enter your option <1/2/3/4/5>:\n");
scanf("%d",&opt);
}
}
原帖由 aiklone1314 于 2009-9-7 10:04 AM 发表
因为题目是要如果按任何号码,除了5,都会从新跳回menu。
就是说计算操作完了后,会在从新逃回menu。
然后,只有按5,程式才会跳出来。
原帖由 aiklone1314 于 2009-9-7 09:07 PM 发表
我知道是 !=5,不过当我execute时,不知道为何他是倒反的,就是说当我放!=5时他反而会从新跳回menu,放==5他就不会这样。
原帖由 宅男-兜着走 于 2009-9-7 09:53 PM 发表
while(opt != 5){} 翻译成人话的话就是 当OPT 不是5 的话请执行。
while loop 不是 if else, 当然不同啊。 我没C的篇写工具也 也没 compiler , 抱歉。 所以我照我懂的跟你说。
int main()
{
...
int opt = 0;
System.out.println("---------\n");
System.out.println("MAIN MENU\n");
System.out.println("---------\n");
System.out.println("1-MATRIX ADDITION\n");
System.out.println("2-MATRIX SUBTRACTION\n");
System.out.println("3-MATRIX MULTIPLICATION\n");
System.out.println("4-MATRIX TRANPOSE\n");
System.out.println("5-EXIT\n");
while(opt!=5){
opt = Integer.parseInt(in.readLine());
switch(opt){
case 1:
System.out.print("doing Addition\n");
break;
case 2:
System.out.print("doing Subtraction\n");
break;
case 3:
System.out.print("doing Multiplication\n");
break;
case 4:
System.out.print("doing Tranpose\n");
break;
}
if(opt!=5){System.out.print("Any command?\n");}
}
System.out.println("\nExit program");
}
}
原帖由 宅男-兜着走 于 2009-9-8 12:53 AM 发表
除此之外呢? 还有没有任何的缩写? 上次你教的类似 java script 的这样 ? true: false; 的方法是好用的。
每个语言都可以如此?
原帖由 duo8668 于 2009-9-9 08:39 PM 发表
#include "stdafx.h"
#include
int main()
{
int add,sub,mul,tran,opt;
printf("---------\n");
printf("MAIN MENU\n");
printf("---------\n");
printf( ...
为何不直接 用
main();
原帖由 duo8668 于 2009-9-11 01:41 AM 发表
对不起对不起。。。
我的意思是为何他那边不 recall main function 而要重新code menu。
就是红色那行换去 main();
原帖由 duo8668 于 2009-9-9 08:39 PM 发表
#include "stdafx.h"
#include
int main()
{
int add,sub,mul,tran,opt;
printf("---------\n");
printf("MAIN MENU\n");
printf("---------\n");
printf( ...
欢迎光临 JBTALKS.CC (https://jbtalks.my/) | Powered by Discuz! X2.5 |