Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions 2_StyleGid/luckyTickets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>

int main(void)
{
int fullCount = 0;
int oneSummCount[28] = { 0 }; // для красоты добавления сумм будем считать с нулевой тоже
int summ;

for (int z1 = 0; z1 <= 9; z1++) { // первая цифра
for (int z2 = 0; z2 <= 9; z2++) { // вторая цифра
for (int z3 = 0; z3 <= 9; z3++) { // третья цифра
summ = z1 + z2 + z3; // сумма текущих 3 цифр
oneSummCount[summ]++;
}
}
}

for (int summ = 1; summ <= 27; summ++) { // а теперь не берем нулевую сумму
fullCount += oneSummCount[summ] * oneSummCount[summ];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это можно сделать сразу при подсчёте сумм. Не надо делать лишний проход.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не совсем понимаю как, если мы сначала добавляем всё, а потом возводи в квадрат

}

printf("Количество счастливых билетиков = %d\n", fullCount);
return 0;
}