#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);
}
Tags: 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;
}
Tags: 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;
}
Tags: 101(上), 程式, 資工二