?? plist.cpp
字號:
////////////////////////////////////////////////////////////////////////////////////////////////
// Plist.cpp //
// 作用:用于計算函數P表 //
// 編寫者:王小龍(00512087) //
// 完成時間:2006、5、5 //
////////////////////////////////////////////////////////////////////////////////////////////////
#include "stdio.h"
#include "stdafx.h"
#include "stdlib.h"
#include "math.h"
#include "time.h"
// 得到P表,返回a(PList 應該在主函數中建立)
//int *Plist =(int*)malloc(sizeof(int)*x_13);
int Get_PList(int *PList, int x_13)
{
int *List = (int*)malloc(sizeof (int)*x_13);
int i,j,a=0;
for (i=0 ; i<x_13 ; i++) // 賦值
{
List[i] = i+1;
}
int x_16 = (int)sqrt (x_13);
List[0]=0; // 單獨考慮1
for(i=1; i<x_16; i++)
{
for(j=i+1; j<x_13 ; j++)
{
if (List[i]!=0 && List[j]!=0)
{
if(List[j] % List[i] ==0)
{
List[j] = 0;
}
}
}
}
int *p = PList;
for (i=0; i<x_13; i++)
{
if(List[i] != 0)
{
*p = List[i];
p++;
a++;
}
}
free(List);
return a; // 返回a值
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -