Archive for 十二月, 2012

using System;
using System.IO;
 
namespace Ex10
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, i, num;
            //N = atoi(argv[1]);
            N = int.Parse(args[0]);
            Random random = new Random();
 
            StreamWriter sw = new StreamWriter("record10.txt");
            for (i = 0; i < N; i++)
            {
                num = random.Next() % 49 + 1;
                Console.WriteLine(num);
                sw.WriteLine(num);
            }
            sw.Close();
        }
    }
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

12
十二月

程式設計一程式 12/12: 練習9 (ex9.c)

   Posted by: admin    in 101(上)程式設計(一)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
    int N, i, num;
    FILE* stream;
    srand( (unsigned) time( NULL ) );
 
    N = atoi(argv[1]);
    printf("Numbers=%d\n", N);
 
    stream=fopen("record.txt", "w+");
 
    for (i=0; i< N;i++)
    {
       num = rand()%49+1;
       printf("%d\n", num);
       fprintf(stream, "%d\n", num);//print to file
    }
 
    fclose(stream);
 
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

import java.io.*;
import java.util.*;
public class Ex9Class {
	public static void main(String[] args) {
		Random random =new Random();
		int N, i, num;
		N = Integer.parseInt(args[0]);
		System.out.printf("Numbers=%d\n", N);
		try
		{
			FileWriter writer = new FileWriter("record.txt");
			PrintWriter pw = new PrintWriter(writer);
 
			for (i=0; i< N; i++)
			{
			  num = random.nextInt()%49;
			  if (num <0) num=-num + 1;
			  else num =num+1;
			  System.out.printf("%d\n", num);
			  pw.printf("%d", num);
			  pw.println();
			}
 
			pw.close();
			writer.close();
		}
		catch(IOException e)
		{
			System.out.println(e.getMessage());
		}
	}
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , , ,

12
十二月

程式設計一程式 12/05: 練習8 (ex8.c)

   Posted by: admin    in 101(上)程式設計(一)

#include <stdio.h>
int main()
{
    printf("Hello Word\n");
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

import java.io.*;
public class Ex8Class {
	public static void main(String[] args) {
		System.out.printf("Hello world\n");
	}
 
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,