Ce este gresit la rezolvarea mea?
Am de rezolvat problema 666 de pe pbinfo si enuntul este:
Se dă o matrice cu n linii și m coloane și elemente numere naturale. Să se determine câte dintre elementele situate pe linii cu indici pari sunt prime.
Date de intrare:
4 3
5 12 10
3 9 1
7 10 1
10 9 3
Date de iesire: 2
Rezolvarea mea:
#include

using namespace std;

int main()
{
unsigned int n,m,i,j,a[100][100],cnt=0,d,ok=0;
cin>>n>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
cin>>a[i][j];
for(i=1;i<=n;i++)
{
if(i%2==0){
for(j=1;j<=m;j++)
{
for(d=2;d<=a[i][j]/2;d++)
{
if(a[i][j]%d==0)
ok=1;
}
if(ok==0)
cnt++;
}
}

}
cout< return 0;
}
Cand rulez imi da 1. Ce e gresit?

Smile Life

Show life that you have a thousand reasons to smile

Get in touch

© Copyright 2024 DOKU.TIPS - All rights reserved.