佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 2415|回复: 42

会做吗?C

[复制链接]
发表于 7-2-2011 06:59 AM | 显示全部楼层 |阅读模式
有人知道怎么做吗?帮帮忙。。。。 lecturer 完全没教到这个,都不知怎么做,
Given the following matrices
M= [2 1]         N = [3 -1]
     [1 2]               [2  -3]
Write a C program to calculate X=3M-2N. The variable M,N and X should be of type integer and the elements in M and N must be initialized in the program. When the program is executed, this result in array X should be displayed on the terminal screen.
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 7-2-2011 07:04 AM | 显示全部楼层
问题2:
write a loop structure that will calculate the sum of all the multiple of four that are less than 50. Write the loop in three different loop structures using:
(a) while loop
(b) do-while loop
(c) for loop

还有,顺便解释 while loop, do-while loop, 和 for loop 的差别。。。。
回复

使用道具 举报

发表于 7-2-2011 08:26 PM | 显示全部楼层
回复 1# yipei




你确定吗 ?不是没有教,而是你的 syllabus 还没有到。。array 是后面的 chapter 来的
回复

使用道具 举报

 楼主| 发表于 7-2-2011 08:34 PM | 显示全部楼层
回复 3# JamesTea


你确定吗 ?不是没有教,而是你的 syllabus 还没有到。。array 是后面的 chapter 来 ...
JamesTea 发表于 7-2-2011 08:26 PM


    可能吧,我不清楚后面的 chapter, 但如果我只学到两个 chapter 的东西,那么又要怎么做哦!
你会吗?
回复

使用道具 举报

发表于 7-2-2011 08:38 PM | 显示全部楼层
C programme 我已经将它全部还给教授了。。 哈哈哈~~~ 忘到一干二净。。
回复

使用道具 举报

 楼主| 发表于 7-2-2011 08:58 PM | 显示全部楼层
回复 5# JamesTea


    geng loh 你,这么好玩的 subject 忘光光了。。。。
这星期四要考 test 1 了,惨了咯,要要怎么读呢? haiz.....
同一天又考 spanish II 不知她会出怎样的问题,
回复

使用道具 举报

Follow Us
发表于 7-2-2011 11:03 PM | 显示全部楼层
回复 5# JamesTea
C Programming 不是对工作最有实际用途的吗?
回复

使用道具 举报

发表于 8-2-2011 02:54 AM | 显示全部楼层
回复  JamesTea
C Programming 不是对工作最有实际用途的吗?
whyyie 发表于 7-2-2011 11:03 PM




但是自从我选上了 pure maths 的 field。。。 我就再也没有用到 C 了,都两年了。。。真的忘记了。。。
回复

使用道具 举报


ADVERTISEMENT

发表于 8-2-2011 02:55 AM | 显示全部楼层
回复  JamesTea


    geng loh 你,这么好玩的 subject 忘光光了。。。。
这星期四要考 test 1 了,惨 ...
yipei 发表于 7-2-2011 08:58 PM




我当然知道好玩,当年做assignment 的时候,做到可以 run 时都不懂高兴到什么样子。。哈哈~~~
回复

使用道具 举报

 楼主| 发表于 8-2-2011 09:52 PM | 显示全部楼层
回复 9# JamesTea


    回复 9# JamesTea


   哈哈,第一次用的时候真的很兴奋,哦!!!!但是学到的,感觉连 C Programming 的 1% 都没有,所以还没感觉到 run programming 真正最好玩的是怎样的,哈哈。。。。
谢天谢地,C Programming test 延迟一个星期,哈哈,那我就有时间再慢慢研究。。。。
回复

使用道具 举报

 楼主| 发表于 15-2-2011 11:32 PM | 显示全部楼层
回复 9# JamesTea


    回复 9# JamesTea

那么这个呢?

#include<stdio.h>
main()
{
    int i,j;
    for(i=3; i<=8; i++)
    {
        for(j=2;j<i; j++)
        {
            if(i%j==0) break;
            if(j%3)
            {
                printf("%d\n",i);
                continue;
            }
        }
    }
}


output 是:
3
5
5
7
7
7


怎么算出来呢?
step 是不是 先看 for(i=3; i<=8; i++) 再来 for(j=2;j<i; j++)?
然后 i%j, if  = 0 (true) then printf("%d\n",i); or if(j%3)?
after if(j%3) 是 printf("%d\n",i); or continue?
continue mean what? continue for first step again? 如是,那么是 for(i=3; i<=8; i++) or  for(j=2;j<i; j++)? 还是 算 i%j?
回复

使用道具 举报

发表于 16-2-2011 02:14 AM | 显示全部楼层
回复  JamesTea


    回复  JamesTea

那么这个呢?

#include
main()
{
    int i,j;
    f ...
yipei 发表于 15-2-2011 11:32 PM



能告诉我 % 是什么意思了吗 ?? 我忘记了。。 只是知道它是 modulo。。可以给我它的含义吗 ??? 就是说如果 3%2 是什么意思??
回复

使用道具 举报

发表于 16-2-2011 02:31 AM | 显示全部楼层
那么这个呢?

#include<stdio.h>
main()
{
    int i,j;
    for(i=3; i<=8; i++)
    {
        for(j=2;j<i; j++)
        {
            if(i%j==0) break;
            if(j%3)
            {
                printf("%d\n",i);
                continue;
            }
        }
    }
}


output 是:
3
5
5
7
7
7


怎么算出来呢?
step 是不是 先看 for(i=3; i<=8; i++) 再来 for(j=2;j<i; j++)?
然后 i%j, if  = 0 (true) then printf("%d\n",i); or if(j%3)?
after if(j%3) 是 printf("%d\n",i); or continue?
continue mean what? continue for first step again? 如是,那么是 for(i=3; i<=8; i++) or  for(j=2;j<i; j++)? 还是 算 i%j?


是的,当你要开始你的 algorithm,一定是先看 for(i=3; i<=8; i++)。。。。i=3 就进入 for(j=2;j<i; j++)。。。

接下来, 如果 if(i%j==0) break 就直接跳出这part 回到 for(i=3; i<=8; i++) 用下一个号码。

如果 false 就进去 if(j%3) 然后 printf("%d\n",i), "printf" 了之后就 "continue" to for(j=2;j<i; j++) for the next j value until j<i, then the whole inner part algorithm go out return to "for(i=3; i<=8; i++)" for the next i value

continue 的 command 是指不管在任何的情况之下,只要你 command 了这个,algorithm 会一直走到你的 program 完为止。。。

如果你的 program 里面有牵涉到 break command。。。 通常 continue 很有用,因为通常 algorithm 遇到 break command 一次过后就会自动 terminate 停了。。。所以配合 continue command 它才能继续走的 program
回复

使用道具 举报

发表于 16-2-2011 02:33 AM | 显示全部楼层
看 algorithm 一定是从 inner part 看到 outer part。。。在 inner part 不断 loop until the condition false, then we will go to outer part and look for the next value. The process goes as the same for the next value..
回复

使用道具 举报

 楼主| 发表于 16-2-2011 06:59 AM | 显示全部楼层
回复 14# JamesTea


    paisei arh, 我看错题目,我想问的是这题:
    Assuming w=4,x=5,y=2,z=1 initially, what will be their values after executing the following code segment:

    if ((x>=0)&&(y<=0));
        z=x*y++;
        x%=3;
        y++;
        w*=3;

    else
        z=y*--x;
        x+=2;
        ++y;
        w=x*y++;
}


答案是:
z=8
x=6
y=4
w=18

我不明白怎么拿到 y=4 和 w=18
为什么y 不是 3? 为什么  w 不是 24?
回复

使用道具 举报

 楼主| 发表于 16-2-2011 07:00 AM | 显示全部楼层
回复 12# JamesTea


  能告诉我 % 是什么意思了吗 ?? 我忘记了。。 只是知道它是 modulo。。可以给我它的含义吗 ??? 就是说如果 3%2 是什么意思??


% mean remainder
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 16-2-2011 07:05 AM | 显示全部楼层
如果 3%2 是什么意思??


如果      3%2=1
回复

使用道具 举报

 楼主| 发表于 16-2-2011 01:05 PM | 显示全部楼层
if x=0,y=0,z=1
what is the value of x, y, z???? after executing the following code.




    if (z=x< || >=&&z==1)
        if (z&&y)
            y=1;
    else
        x=1;


我该怎么算 value of x, y, z 呢?
回复

使用道具 举报

 楼主| 发表于 16-2-2011 01:11 PM | 显示全部楼层
If x=4, y=0 and z=2
找 value of x,y,z after executing the following code:


if (z=0 || x && !y)
    if (!z)
       y=1;
else
    x=2




还有,其实这些题目都是要怎么算的呢? 不是很明白。。。。
而且 lecturer 教的是很容易的!
回复

使用道具 举报

发表于 16-2-2011 03:15 PM | 显示全部楼层
本帖最后由 JamesTea 于 16-2-2011 03:21 PM 编辑
回复  JamesTea


    paisei arh, 我看错题目,我想问的是这题:
   Assuming w=4,x=5,y=2,z=1 initially, what will be their values after executing the following code segment:

    if ((x>=0)&&(y<=0));
        z=x*y++;
        x%=3;
        y++;
        w*=3;

    else
        z=y*--x;
        x+=2;
        ++y;
        w=x*y++;
yipei 发表于 16-2-2011 06:59 AM



我也觉得你的答案有错, suppose y=3, otherwise 你 z 的答案不会是 18 而是 24 。。。你确定你没有抄错答案 ?

w=4,x=5,y=2,z=1 initially has already told you that it will not go through the "if" condition since y is not <=0.
So we look at the "else" algorithm...

z=y*--x   ->z=y*(x-1=x)=2*4 = 8
x+=2      -> x=x+2 = 4+2 = 6
++y        -> y+1=y = 3
w=x*y++   -> w=x*(y=y+1)=6*4 = 24
回复

使用道具 举报

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

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 24-4-2024 11:30 PM , Processed in 0.072073 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表