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

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

热度:158   发布时间:2007-07-03 17:17:43.0
乘法题:
char pfile[10][3]={"00","07","14","21","28","35","42","49","56","63"};



GetSum(char a[4],int b)
{
int i,s=0,j=0,n=0,t,p;
char temp[2];
char sum[10],tmpn[3],ret[10];

for(i=strlen(a)-1;i>=0;i--)
{
if(a[i]=='.')
{
p=i;
continue;
}

temp[0]=a[i];
temp[1]='\0';


sprintf(tmpn,"%d\0",atoi(pfile[atoi(temp)])+n);
if(strlen(tmpn)==1) //没有进位
{
tmpn[2]='\0';
tmpn[1]=tmpn[0];
tmpn[0]='0';
}

sum[j]=tmpn[1];
sum[j+1]=tmpn[0];
sum[j+2]='\0';

temp[0]=tmpn[0];
temp[1]='\0';

n=atoi(temp);
j++;

printf("%s\n",sum);
}


t=0;
for(i=j;i>=0;i--)
{
ret[t]=sum[i];
if(p!=0)
if(t==p)
{
t++;
ret[t]='.';
}
t++;
}
ret[t]='\0';
printf("%f\n",atof(ret));
}

int main()
{
int b=7;
char a[4];
int i;

printf("input a numble(max len is 4):");
scanf("%s",a);

GetSum(a,b);
}

----------------解决方案--------------------------------------------------------
谢谢楼上的各位.......
问题4,问题5有人会吗??
帮帮忙啊!!!!!!!!!
----------------解决方案--------------------------------------------------------
mp3aaa 朋友:
16--10
8--10也是类似
#include<stdio.h>
#include<math.h>
main()
{
char a[10];
long k=0,i,j=0,x,y;
scanf("%s",a);
i=strlen(a)-1;
while(i+1)
{ x=long(pow(16.0,j++)); //我运行的时候怎么这里老是报错的...................
y=a[i]>='0'&&a[i]<='9'?a[i--]-'0':a[i--]-'A'+10;
k+=x*y;
printf("%d,%d\n",x,y);我测试数据时用的
}
printf("%ld",k);
}


----------------解决方案--------------------------------------------------------
你用的 TC编译器吧
注意输入16进制数时字母要大写
你吧
这样就对了 是编译器的事
#include<stdio.h>
#include<math.h>
main()
{
char a[10];
long k=0,i,j=0,x,y;
scanf("%s",a);
i=strlen(a)-1;
while(i+1)
{ x=(long)pow(16.0,j++); //我运行的时候怎么这里老是报错的...................
y=a[i]>='0'&&a[i]<='9'?a[i--]-'0':a[i--]-'A'+10;
k+=x*y;
printf("%d,%d\n",x,y);
}
printf("%ld",k);
}

[此贴子已经被作者于2007-7-3 21:31:04编辑过]


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

呵呵,果然不错!!
能能给别的题目也看看.......谢谢...........


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

怎么没人给俺看看了啊................


----------------解决方案--------------------------------------------------------
问题5写给你呢,问题2也是艾,其他的就无能为力了
----------------解决方案--------------------------------------------------------

呵呵,谢谢了.....


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

QUESTION #3

1. Considering compacting memory while managing equal-sized blocks. Assume each block consists of a data field and a pointer field, and that we have marked every block currently in use. The blocks are currently located between memory locations a and b. We wish to relocate all active blocks so that they occupy contiguous memory starting at a. In relocating a block remember that the pointer field of any block pointing to the relocated block must be updated. Design an optimized C program for compacting the blocks.

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



有会的帮忙看下,多谢!!!!!!!!!!!!


----------------解决方案--------------------------------------------------------
这题要做什么我还是没有明白阿,大学数学全忘记了,亏对大学数学老师阿
----------------解决方案--------------------------------------------------------
  相关解决方案