Предмет: Информатика,
автор: danil351
нужно перевести на си
program prog;
uses crt;
const n = 10;
var a: array[1..n] of integer;
i: integer;
count: integer; b
egin clrscr;
randomize;
count := 0;
for i := 1 to n do begin a[i] := random(n) + 1;
write(a[i], ' ');
if ((not odd(i)) and odd(a[i])) then inc(count);
end;
writeln;
writeln('Count: ', count);
readkey; end.
Ответы
Автор ответа:
1
#include <stdio.h>
#include <stdlib.h>
main(){
#define N 10
int i,count=0;
int a[N];
srand(time(0));
for (i=0; i<N; i++) {
a[i]=rand()%(i+1)+1;
printf("%d ",a[i]);
if ((i%2==0) && (a[i]%2!=0)) count++;
}
printf("\nCount=%d\n",count);
system("pause");
}
#include <stdlib.h>
main(){
#define N 10
int i,count=0;
int a[N];
srand(time(0));
for (i=0; i<N; i++) {
a[i]=rand()%(i+1)+1;
printf("%d ",a[i]);
if ((i%2==0) && (a[i]%2!=0)) count++;
}
printf("\nCount=%d\n",count);
system("pause");
}
Интересные вопросы
Предмет: Английский язык,
автор: 12345678коаг7д
Предмет: Английский язык,
автор: akndkandaknd
Предмет: Английский язык,
автор: ksenyamihailova
Предмет: Физика,
автор: arinaminsk2005s
Предмет: Биология,
автор: alekseev2004alekseev