Nvidia 面试题之一
大概的题目是这样的:
实现一个函数 void * storenum(struct node* list,int n , int m);
【The|Nvidia 面试题之一】作用于分式值小于1的除法. eg: 1/4 = 0.25 这里 m = 4, n = 1 把输出的结果储存到list链表里面
/****************************************
Code writer: EOF
code date: 2014.10.11
e-mail: jasonleaster@gmail.com If you find bugs in my code,
please touch me, thank you : )
****************************************/
#include
#include struct node
{
int num;
struct node* next;
};
int storenum(struct node* list,int m,int n);
int main()
{
struct node header;
storenum(&header,1,16);
struct node *p_node = &header;
/*
** Print out answer.
*/
for(;
(p_node->next);
)
{
printf("%d ",p_node->num);
p_node = p_node->next;
} /*
** Free List we allocated.
*/
struct node *del_node = NULL;
for(p_node = header.next;
(header.next);
)
{
del_node = header.next;
header.next = del_node->next;
free(del_node);
} return 0;
}int storenum(struct node* list,int m,int n)
{
if(!list)
{
return 0;
} int factor = 10;
if(m >= n)
{
printf("Hey guys read again the rule of this game.!\n");
}
else
{list->num= 0;
//0.***
list->next = NULL;
for(;
m%n != 0;
)
{
list->next = (struct node*)malloc(sizeof(struct node));
list->next->next = NULL;
list = list->next;
list->num =m*factor/n;
m = (m * factor)%n;
}list->next = (struct node*)malloc(sizeof(struct node));
list->next->next = NULL;
list = list->next;
list->num =m*factor/n;
m = (m * factor)%n;
} return 0;
}
文章图片
推荐阅读
- c/c++|有感 Visual Studio 2015 RTM 简介 - 八年后回归 Dot Net,终于迎来了 Mvc 时代,盼走了 Web 窗体时代...
- C/C++|C/C++ basis 02
- Qt实战|Qt+OpenCV联合开发(二十一)--图像翻转与旋转
- Qt实战|Qt+OpenCV联合开发(十四)--图像感兴趣区域(ROI)的提取
- Qt实战|Qt+OpenCV联合开发(十三)--通道分离与合并
- opencv|Qt+OpenCV联合开发(十六)--图像几何形状绘制
- Qt实战|Qt+OpenCV联合开发(十七)--随机数与随机颜色
- SNAT的MASQUERADE地址选择与端口选择
- IPTABLES的连接跟踪与NAT分析
- IPVS分析