首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

搜狗的笔考试题

2012-09-20 
搜狗的笔试题#include stdio.h#include assert.h#include malloc.h#define NUM 10#define NEGATIVE_

搜狗的笔试题

#include <stdio.h>#include <assert.h>#include <malloc.h>#define NUM 10#define NEGATIVE_INF -10000long MaxMultiple(long *arrayPtr, int n){  assert(arrayPtr != NULL && n != 0);  int itor;  long max = NEGATIVE_INF;    int *ptr1 = (int *)malloc(n * sizeof(int));  assert(ptr1 != NULL);    int *ptr2 = (int *)malloc(n * sizeof(int));  assert(ptr2 != NULL);    ptr1[0] = 1;  ptr2[n - 1] = 1;    for(itor = 1; itor < n; itor++)  {     ptr1[itor] = ptr1[itor - 1] * arrayPtr[itor - 1];  }    for(itor = n - 2; itor >= 0; itor--)  {    ptr2[itor] = ptr2[itor + 1] *arrayPtr[itor + 1];  }    for(itor = 0; itor < n; itor++)  {    arrayPtr[itor] =ptr1[itor] * ptr2[itor];  }    for(itor = 0; itor < n; itor++)  {if(arrayPtr[itor] > max)  {    max = arrayPtr[itor];  }  }  free(ptr1);  free(ptr2);  return max;} int main(){  long a[NUM] = {2,4,3,8,5,3,2,3,6,7};  int itor;  long max;  max = MaxMultiple(a,NUM);  printf("%d\n",max);  for(itor = 0; itor < NUM; itor++)  {      printf("%ld ",a[itor]);  }  printf("\n");  return 0;}


热点排行