if (mistake) { printf("Invalid code.\n"); return -1; } }
printf("Fixed code: %s\n", input); for (i = 0; i < len; i++) if (i + 1 == b) b <<= 1; else info[info_pos++] = input; info[info_pos] = '\0'; printf("Informational string: %s\n", info); return 0; }
Uses crt; const N=10; var a:array [1..N] of integer; x,k:integer; begin k:=0; for x:=1 to 10 do begin a[x]:=random(99)+1; writeln('a[',x,']:',a[x]); if a[x] mod 3=0 then inc(k); end; writeln('Количество элементов, кратных 3:',k); end. --- Для турбо паскаль: uses crt; const N=10; var a:array [1..N] of integer; x,k:integer; begin clrscr; k:=0; for x:=1 to 10 do begin a[x]:=random(100)+1; writeln('a[',x,']:',a[x]); if a[x] mod 3=0 then inc(k); end; writeln(k); readln; end.
#include <stdlib.h>
char input[1024];
int len;
int find_mistake()
{
int i, mistake = 0;
for (i = 0; i < len; i ++)
if (input == '1')
mistake ^= i + 1;
return mistake;
}
int main()
{
int i, mistake = 0;
char info[1024];
int info_pos = 0;
int b = 1;
printf("Enter code: ");
scanf("%s", input);
len = strlen(input);
for (i = 0; i < len; i++)
if (input != '0' && input != '1')
{
printf("Invalid code.\n");
return -1;
}
mistake = find_mistake();
if (mistake)
{
input[mistake - 1] ^= '0' ^ '1';
mistake = find_mistake();
if (mistake)
{
printf("Invalid code.\n");
return -1;
}
}
printf("Fixed code: %s\n", input);
for (i = 0; i < len; i++)
if (i + 1 == b)
b <<= 1;
else
info[info_pos++] = input;
info[info_pos] = '\0';
printf("Informational string: %s\n", info);
return 0;
}
const N=10;
var a:array [1..N] of integer;
x,k:integer;
begin
k:=0;
for x:=1 to 10 do
begin
a[x]:=random(99)+1;
writeln('a[',x,']:',a[x]);
if a[x] mod 3=0 then inc(k);
end;
writeln('Количество элементов, кратных 3:',k);
end.
---
Для турбо паскаль:
uses crt;
const N=10;
var a:array [1..N] of integer;
x,k:integer;
begin
clrscr;
k:=0;
for x:=1 to 10 do
begin
a[x]:=random(100)+1;
writeln('a[',x,']:',a[x]);
if a[x] mod 3=0 then inc(k);
end;
writeln(k);
readln;
end.
Скрины, как должна работать программа, приложила.