当前位置: 代码迷 >> C语言 >> 公司给的几道C语言方面的题目
  详细解决方案

公司给的几道C语言方面的题目

热度:288   发布时间:2007-07-06 22:30:38.0
turbo c2.0在切换或退出时老是死机,是turbo c2.0死了,不是机器死了,怎么回事,请高手详细指点,跪谢!
----------------解决方案--------------------------------------------------------
以下是引用chinahgcq在2007-7-6 13:33:23的发言:

1. Assume that your CPU does not have multiply and divide units. You can not use function in C that will not use multiply, divide and modulo operators. Write the following programs:

a) multiply any given number by 7

b) divide any given number by 7

2. Make sure that you write the most optimized code, and give full description of any potential errors that can happen using your function.


For 1(a)
typedef ElemType int;
#define NUM 7;
ElemType Multiply(ElemType Num,ElemType n)
{
ElemType Result;
for(int i=0;i<NUM;i++)
{
Result +=n;
}
return Result;
}

then the result is NUM*n,but this methord is not good,as it's not fast,lets try another one;

ElemType Multiply(ElemType NUM,ElemType n)
{
ElemType Result,n1,n2;
n1=n<<3; //that's n1=n*8;
n2=n; //that's n2=n*1;
Result=n1-n2; //that's Reuslt=n*8-n*1=7*n;

return Result;
}



For 1(b),it's the same


这个方法有点难想出来.
尤其是在做除法的时候.
果然厉害


----------------解决方案--------------------------------------------------------

谢谢楼上的各位........学到不少东西..........
难道这到题目就没有人会做吗??


QUESTION #4

1. Write a program in C to multiply two linear matrices. This program should take as input the dimensions of each matrix, as well as the components of each matrix. Remember to write the most optimal code possible. Use the following matrices as a test:

1 0

-2 3 0 6 1

5 4 3 8 -2

0 1


----------------解决方案--------------------------------------------------------
不是不会做,你上面写的线性矩阵的写法让人摸不着头脑 ,把它写清楚点,用两个式子分别表示出来,不要写在一块
----------------解决方案--------------------------------------------------------
第一题跟自动机接收合法字符差不多道理,,学过编译原理都知道怎么做,,

最后一题明显就是用位移运算,(鄙人的第一反应)

----------------解决方案--------------------------------------------------------

我刚才还以为进了一个打开错误的网页呢


----------------解决方案--------------------------------------------------------
  相关解决方案