Другие языки программирования и технологии

c++ не работает программа

Нужно сделать программу которая бы считала сколько раз встречается цифра 7 во всех числах двухмерного массива и их сумму. Вроде все правильно сделал но считает неправильно. Помогите найти ошибку.

#include
#include
#include
#include
using namespace std;

int main()
{
srand(time(NULL));
int z[10][10];
int i, j;
int kol=0;
int sum=0;
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
z[i][j]=rand()%2000-1000;
cout << " " << z[i][j] << " ";
}
cout << endl;
}
for (i=0; i<10; i++)
{for (j=0; j<10; j++)
{
if((z[i][j] / 100 == 7))
{
kol=kol + 1;
}
if(((z[i][j] % 100)/10) == 7)
{
kol=kol + 1;
}
if((z[i][j] % 10) == 7)
{
kol=kol + 1;
}
}
cout << endl;
}
sum=kol*7;
cout << "kolichestvo=" << kol << endl ;
cout << "summa=" << sum << endl ;
}
нужно исправит ошибку что бы работало
АЗ
Анатолий Зайдель
14 602
Лучший ответ
Игорь Гуров Где ошибка ?
#include
#include "time.h"

using namespace std;

int count_7 (int chislo){
int sum = 0; chislo = abs(chislo);
while(chislo){
if(chislo%10 == 7) sum++;
chislo/=10;
}
return sum;
}

int main()
{
srand(time(NULL));
int z[10][10];
int i, j;
int kol=0;
int sum=0;
for (i=0; i<10; i++)
{
for (j=0; j<10; j++)
{
z[i][j]=rand()%2000-1000;
cout << " " << z[i][j] << " ";
}
cout << endl;
}
for (i=0; i<10; i++)
{for (j=0; j<10; j++)
{
kol += count_7(z[i][j]);
}
cout << endl;
}
sum=kol*7;
cout << "kolichestvo=" << kol << endl ;
cout << "summa=" << sum << endl ;
}
#include <iostream>
#include <random>

using namespace std;

unsigned count7(int a){
if(a < 0) return count7(-1*a);
if(a == 0) return 0;
return (a % 10 == 7) + count7(a/10);
}

int main() {
srand(time(NULL));
int z[10][10];
int kol = 0;
for (int i = 0; i < 10; i++){
for (int j = 0; j < 10; j++){
z[i][j] = rand() % 2000 - 1000;
cout << " " << z[i][j] << " ";
}
cout << endl;
}

for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
kol += count7(z[i][j]);
}
}

cout << "Ammount: " << kol << endl;
cout << "Sum: " << kol*7 << endl;

return 0;
}
Сергей Антипин
Сергей Антипин
11 157