Posts Tagged ‘101(上)’

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(int argc, char *argv[])
{
    int num, N;
 
 
    printf("A random number < %d -> %d", N, num);
    return 0;
}
===========================
#include <stdio.h>
int main()
{
   int i, ret, score;
   int max=0;
   FILE * stream;
   char filename[20]="score.txt";
 
   stream=fopen(filename, "r");
   ret=fscanf(stream,"%2d \n", &score);
...
   printf("The max score is %d", max);
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

2
一月

程式設計一程式 12/30: quiz2b

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

#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    int num;
    int upper = 10;
    int digit = 1;
    printf("Input a number:");
    scanf("%d", &num);
 
    if (num <upper)
       printf("The number %d is %d digits", num, digit);
 
    while (num   upper)
    {
          upper*= 10
          digit++
          if (num <upper)
          printf("The number %d is %d digits", num, digit)
    }
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

2
一月

程式設計一程式 12/30: quiz2a

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

#include <stdio.h>
#include <stdlib.h>
 
int main(int argc, char *argv[])
{
    int a, b, c, d;
    int sum;
    a = atoi(argv[1]);
    b = atoi(argv[2]);
    c = atoi(argv[3]);
    d = atoi(argv[4]);
 
    sum = a*a*a*a + b*b*b + c*c +d
 
    printf("(%d, %d, %d, %d) ans=%d", a, b, c, d, sum)
    return 0;
}

bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark bookmark

Tags: , ,

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: , ,