#include <iostream>
#include <math.h>

using namespace std;

int main()
{
 int n,cont=1,i=3,reg=2;
 char flag;
 cin>>n;
 int s[200000];
 s[0]=2;
 while(cont<n){
  flag=0;
  for(int j=0;j<cont;j++){
   if(i%s[j]==0){flag=1;break;}
   if(s[j]>=sqrt(i))break;
  }
  if(flag==0){reg=i;s[cont]=reg;cont++;}
  i+=2;
 }
 cout<<reg<<endl;
    system("pause");
    return 0;
}

h881068 發表在 痞客邦 留言(0) 人氣()

#include <iostream>
using namespace std;

int main()
{
 int n,buf,i;
    cout<<"請輸入N:";
 cin>>n;
    cout<<"小於N的完美數有:";
 for(i=1;i<=n;i++){
  buf=0;
  for(int j=1;j<i;j++){
   if(i%j==0)buf=buf+j;
  }
  if(buf==i)cout<<i<<" ";
 }
 cout<<endl;
 system("pause");
 return 0;
}

h881068 發表在 痞客邦 留言(0) 人氣()

Private Sub Form_Load()
Me.AutoRedraw = True
Line (0, 0)-(Me.ScaleWidth, Me.ScaleHeight), RGB(255, 0, 0), BF
Line (0, 0)-(Me.ScaleWidth / 2, Me.ScaleHeight / 2), RGB(0, 0, 255), BF
Me.FillStyle = 0: Me.FillColor = &HFFFFFF
Circle (Me.ScaleWidth / 4, Me.ScaleHeight / 4), Me.ScaleHeight / 8, &HFFFFFF
For i = 0 To 330 Step 30
 Call draw(3 * Me.ScaleHeight / 16 - Me.ScaleHeight / 32, CDbl(i))
Next i
End Sub

Sub draw(length As Integer, d As Double)
x = Me.ScaleWidth / 4 + length * Sin((3.14159 * d) / 180)
y = Me.ScaleHeight / 4 + length * Cos((3.14159 * d) / 180)
Circle (x, y), 10, &H0
Dim xx(2) As Double, yy(2) As Double
For j = 1 To Me.ScaleHeight / 32 Step 10
 c = d + 120: If c >= 360 Then c = c - 360
 xx(0) = x + j * Sin(3.14159 * (c) / 180)
 yy(0) = y + j * Cos(3.14159 * (c) / 180)
 c = d + 0: If c >= 360 Then c = c - 360
 xx(1) = x + j * Sin(3.14159 * (c) / 180)
 yy(1) = y + j * Cos(3.14159 * (c) / 180)
 c = d + 240: If c >= 360 Then c = c - 360
 xx(2) = x + j * Sin(3.14159 * (c) / 180)
 yy(2) = y + j * Cos(3.14159 * (c) / 180)
 For i = 0 To 1
  Line (xx(i), yy(i))-(xx(i + 1), yy(i + 1)), &HFFFFFF
 Next i
 Line (xx(2), yy(2))-(xx(0), yy(0)), &HFFFFFF
Next j
End Sub

Private Sub Form_Resize()
Cls
Form_Load
End Sub

h881068 發表在 痞客邦 留言(0) 人氣()

public class work4{//求最大公因數、最小公倍數
   public static void main (String[] argv){
    int[] a=new int[argv.length];
    int sum=1;
    for(int k=0;k<argv.length;k++){
     a[k]=Integer.parseInt(argv[k]);
     sum=sum*a[k];}
    int tes=0;
    for(int i=0;i<argv.length;i++){
   if(tes<a[i]){tes=a[i];}
   }
    Drgo b=new big();
    for(int i=tes;i>0;i--){
     int f=0;
     for(int j=0;j<argv.length;j++){
      if(a[j]%i>0){f++;}
     }
     if(f==0){b.ccc(i);break;}
    }
    God c=new sm();
    for(int i=tes;i<sum;i++){
     int g=0;
     for(int j=0;j<argv.length;j++){
      if(i%a[j]>0){g++;}
     }
     if(g==0){c.ccc(i);break;}
    }
  }
 }
abstract class Drgo{
 abstract public void ccc(int h);
}
class big extends Drgo{
 public void ccc(int h){
  System.out.println("最大公因數為"+h);
  }
}
interface God{
 public void ccc(int h);
}
class sm implements God{
 public void ccc(int h)
  {System.out.println("最小公倍數為"+h);}
}

h881068 發表在 痞客邦 留言(0) 人氣()

import java.io.File;
public class work2{
 public static void main(String[] argv) {
 File f=new File(argv[0]);
 if(!f.exists())
  {System.out.println("路徑輸入錯誤!!");
   return;
  }
 if(f.isDirectory())//是否為資料夾
  {
    dir(f,1);
  }
 }
 public static void dir(File son,int m){
  File s;String rn="";
  for(int i=0;i<m;i++){rn=rn+" ";}
  System.out.print("/");System.out.println("");
  String[] strs=son.list();
   for(int i=0;i<strs.length;i++){
    s=new File(son+"/"+strs[i]);
    if(s.isDirectory()){
     System.out.println();m+=1;System.out.print(rn+strs[i]);}
    else{System.out.print(strs[i]+" ");}
    if(s.isDirectory()){dir(s,m);}
   }
  System.out.print(")");m=m-1;
 }
}

h881068 發表在 痞客邦 留言(0) 人氣()

package drgo;
public class work5{
 public void PID(String id){
  int[] num=new int[10];
  int[] rdd={10,11,12,13,14,15,16,17,34,18,19,20,21,22,35,23,24,25,26,27,28,29,32,30,31,33};
        id=id.toUpperCase();
  if(id.charAt(0)<'A'||id.charAt(0)>'Z'){
         System.out.println("第一個字錯誤!!");return;
        }
        if(id.charAt(1)!='1' && id.charAt(1)!='2'){
         System.out.println("第二個字錯誤!!");return;
        }
        for(int i=1;i<10;i++){
         if(id.charAt(i)<'0'||id.charAt(i)>'9'){
          System.out.println("輸入錯誤!!");return;
         }
        }
  for(int i=1;i<10;i++){
   num[i]=(id.charAt(i)-'0');
  }
  num[0]=rdd[id.charAt(0)-'A'];
  int sum=((int)num[0]/10+(num[0]%10)*9);
  for(int i=0;i<8;i++){
   sum+=num[i+1]*(8-i);
  }
  if(10-sum%10==num[9]){
   System.out.println("身分證號正確");}
  else{
   System.out.println("身分證號錯誤");}
 }
}

h881068 發表在 痞客邦 留言(0) 人氣()

#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

int main()
{
 int a,bit=0;
 int b[99];
 cin>>a;
 while(a>1){
  b[bit]=a%2;
  bit++;
  a=(int)a/2;
 }
    b[bit]=a;
 for(int i=bit;i>=0;i--)cout<<b[i];
 cout<<endl<<"猜數字"<<endl;
    srand(time(NULL));
 int c[4],d[4],e,ga,gb;
 for(i=0;i<4;i++)c[i]=rand()%10;
    do{
     cin>>e;
        d[0]=(int)(e/1000);
  e-=d[0]*1000;
  d[1]=(int)(e/100);
  e-=d[1]*100;
  d[2]=(int)(e/10);
  e-=d[2]*10;
  d[3]=e;
  ga=0;gb=0;
  for(i=0;i<4;i++){
   for(int j=0;j<4;j++){
    if(d[i]==c[j]){
     if(i==j)ga++;else gb++;
    }
   }
  }
  cout<<ga<<"A"<<gb<<"B"<<endl;
 }while(d[0]!=c[0]||d[1]!=c[1]||d[2]!=c[2]||d[3]!=c[3]);
 cout<<"Bingo!"<<endl;
 system("pause");
 return 0;
}

h881068 發表在 痞客邦 留言(0) 人氣()

//輸入N值,並印出第N個質數,比如第一個質數=2,第二個=3
//本範例執行效率很高
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
 int n,cont=1,i=3,reg=2;
 char flag;
 cin>>n;
 int s[200000];
 s[0]=2;
 while(cont<n){
  flag=0;
  for(int j=0;j<cont;j++){
   if(i%s[j]==0){flag=1;break;}
   if(s[j]>=sqrt(i))break;
  }
  if(flag==0){reg=i;s[cont]=reg;cont++;}
  i+=2;
 }
 cout<<reg<<endl;
    system("pause");
    return 0;
}

h881068 發表在 痞客邦 留言(0) 人氣()