mirror of
https://github.com/theoleuthardt/learningC.git
synced 2026-06-13 09:37:53 +00:00
Initial commit
This commit is contained in:
commit
826d4c8c9d
81 changed files with 7268 additions and 0 deletions
32
uebung6/aufgabe3.c
Normal file
32
uebung6/aufgabe3.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
int main() {
|
||||
// A3: Lottozahlen ziehen und in einer Datei speichern
|
||||
FILE *fptr = fopen("../Lottozahlen.txt", "w");
|
||||
if (fptr == NULL) {
|
||||
printf("Not able to open the file.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
time_t now;
|
||||
now = time(0);
|
||||
int numbers[10];
|
||||
//Normale Zahlen
|
||||
fprintf(fptr, "%s", ctime(&now));
|
||||
for(int i = 0 ; i < 7 ; i++ ) {
|
||||
numbers[i] = rand() % 49 +1;
|
||||
for (int n = 0; n < 7; n++) {
|
||||
if (numbers[i] == numbers[n]) {
|
||||
numbers[i] = rand() % 49 +1;
|
||||
}
|
||||
}
|
||||
fprintf(fptr,"%d ", numbers[i]);
|
||||
}
|
||||
|
||||
fprintf(fptr, "\n");
|
||||
fclose(fptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue