C-Programmierung
Array Beispiel
← Sizeof Operator | ● | Zeichenketten (C-Strings) →
Ziehung der Lottozahlen:
#include <stdio.h>
#include <stlib.h>
static const int n=49;
char lotto[n]={0};
int main()
{
int i;
srand(time(NULL));
for (i=0; i<7; i++)
{
z=rand()%49+1;
if (!lotto[z-1])
lotto[z-1]=1;
else
i--;
}
printf("7 out of 49: ");
for (i=0; i<n; i++)
if (lotto[i])
printf("%d ", i+1);
printf("\n");
return(0);
}
#include <stlib.h>
static const int n=49;
char lotto[n]={0};
int main()
{
int i;
srand(time(NULL));
for (i=0; i<7; i++)
{
z=rand()%49+1;
if (!lotto[z-1])
lotto[z-1]=1;
else
i--;
}
printf("7 out of 49: ");
for (i=0; i<n; i++)
if (lotto[i])
printf("%d ", i+1);
printf("\n");
return(0);
}