w 很难的C!!!对菜鸟难如登天?对老鸟易如反掌?我是菜鸟! - 电脑语言编程讨论区 JBTALKS.CC -->
Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 4100|回复: 27
打印 上一主题 下一主题

很难的C!!!对菜鸟难如登天?对老鸟易如反掌?我是菜鸟!

[复制链接]

55

主题

0

好友

2027

积分

白金长老

Rank: 10

跳转到指定楼层
1#
发表于 2009-9-6 11:43 PM |只看该作者 |正序浏览
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);
}
}


p/s:应该是C不是C++,谢谢三楼大大的提醒!

[ 本帖最后由 aiklone1314 于 2009-9-7 10:09 AM 编辑 ]




收藏收藏0

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

28#
发表于 2009-9-11 11:57 AM |只看该作者
if 和 while 最大的不同就是
比如说
if this->Text == this->Text {Messagebox.Show();}
这个只会执行一次
while this->Text == this->text{messagebox.show():}
这个会跳很多个出来,而且当你尝试关掉该程序,就会not responding
可以说是用掉整个程序的效能
p/s virus 最佳

switch case??google 不是有很多吗?
比如说我要探测textbox1的字

switch(textbox1->Text)
{
case "goodhermit95"{
//里面的字是goodhermit95
}
case "super-tomato"
//里面的字是super-tomato,你要做什么你自己看
}
}

continue 和break的意思是
比如说在循环函数中,continue就是继续循环,break就是跳过循环,继续指令
while(xxxx)
{
//如果在这里continue,他就会继续
//a
}
如果在 a break,就会跳来这里


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

27#
发表于 2009-9-11 02:44 AM |只看该作者
原帖由 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(); 这样的方法 在其他语言也适用? paiseh 我也是菜鸟。


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

26#
发表于 2009-9-11 01:44 AM |只看该作者
原帖由 duo8668 于 2009-9-11 01:41 AM 发表
对不起对不起。。。

我的意思是为何他那边不 recall main function 而要重新code menu。
就是红色那行换去  main();


這是新手還不熟悉編寫的過程


回复

使用道具 举报

10

主题

0

好友

862

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

25#
发表于 2009-9-11 01:41 AM |只看该作者
对不起对不起。。。

我的意思是为何他那边不 recall main function 而要重新code menu。
就是红色那行换去  main();

[ 本帖最后由 duo8668 于 2009-9-11 01:43 AM 编辑 ]


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

24#
发表于 2009-9-9 08:44 PM |只看该作者
原帖由 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();




int main 是 C 的標準入口函數, 而 main 即 void/int main 的縮寫雖然也可以, 但有些編譯器無法對不明確的函數類型進行編譯

p/s: http://www.safercode.com/blog/20 ... n-vs-void-main.html

[ 本帖最后由 Super-Tomato 于 2009-9-9 08:52 PM 编辑 ]


回复

使用道具 举报

10

主题

0

好友

862

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

23#
发表于 2009-9-9 08:39 PM |只看该作者
#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);


为何不直接 用
main();

}
}


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

22#
发表于 2009-9-8 12:17 PM |只看该作者
原帖由 宅男-兜着走 于 2009-9-8 02:00 AM 发表
你是对的,我没写,我知道try catch 没有不行。


哦... 原來是你省略掉了哦


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

21#
发表于 2009-9-8 02:00 AM |只看该作者

回复 #20 Super-Tomato 的帖子

你是对的,我没写,我知道try catch 没有不行。


回复

使用道具 举报

7

主题

1

好友

5108

积分

一流名嘴

Rank: 12Rank: 12Rank: 12

20#
发表于 2009-9-8 01:06 AM |只看该作者
原帖由 宅男-兜着走 于 2009-9-8 12:53 AM 发表
除此之外呢? 还有没有任何的缩写?  上次你教的类似 java script 的这样 ? true: false; 的方法是好用的。

每个语言都可以如此?


哦, 大部分由 C 或 Java 所衍生出來的語言都可以支援 ?:
++, += 這類的 operator 你應該都清楚了, 大致上也沒甚麼縮寫方式



原帖由 宅男-兜着走 于 2009-9-8 12:59 AM 发表
java 可以, 已经证实了。


  你沒用 exception 可以執行??
可否把你完整的 Java coding 貼出來??


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2025-10-14 05:04 AM , Processed in 0.121581 second(s), 28 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部