<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=text/html;charset=iso-8859-1 http-equiv=Content-Type>
<STYLE><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Verdana
}
--></STYLE>
<META name=GENERATOR content="MSHTML 8.00.6001.18882"></HEAD>
<BODY style="PADDING-LEFT: 10px; PADDING-RIGHT: 10px; PADDING-TOP: 15px"
id=MailContainerBody class=hmmessage leftMargin=0 topMargin=0
CanvasTabStop="true" name="Compose message area">
<DIV><FONT face=Arial>Fijate que no inicializas cont=0 en cada vuelta. Aca te
mando la corrección: </FONT></DIV>
<DIV><FONT face=Arial></FONT> </DIV>
<DIV><FONT color=#008000 size=2><FONT color=#008000 size=2>
<P>// Numeros_Primos.cpp</P>
<P>//</P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT
color=#a31515 size=2>"stdafx.h"</P></FONT></FONT><FONT color=#0000ff
size=2><FONT color=#0000ff size=2>
<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT
color=#a31515 size=2><time.h></P></FONT></FONT><FONT color=#0000ff
size=2><FONT color=#0000ff size=2>
<P>#include</FONT></FONT><FONT size=2> </FONT><FONT color=#a31515 size=2><FONT
color=#a31515 size=2><iostream.h></FONT></FONT></P>
<P><FONT color=#a31515 size=2><FONT color=#a31515 size=2> </P>
<P></P></FONT></FONT><FONT color=#0000ff size=2><FONT color=#0000ff size=2>
<P>using</FONT></FONT><FONT size=2> </FONT><FONT color=#0000ff size=2><FONT
color=#0000ff size=2>namespace</FONT></FONT><FONT size=2> std;</P></FONT><FONT
color=#0000ff size=2><FONT color=#0000ff size=2>
<P>int</FONT></FONT><FONT size=2> _tmain(</FONT><FONT color=#0000ff size=2><FONT
color=#0000ff size=2>int</FONT></FONT><FONT size=2> argc, _TCHAR* argv[])</P>
<P>{</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2> int</FONT></FONT><FONT size=2>
a,b,c,d,n,v,j,k,cont,r,matriz[10][10],vector[10],cont2=0;</P>
<P> printf(</FONT><FONT color=#a31515 size=2><FONT
color=#a31515 size=2>"\n\n\t"</FONT></FONT><FONT size=2>); </FONT><FONT
color=#008000 size=2><FONT color=#008000 size=2>//Generamos la
matriz....</P></FONT></FONT><FONT size=2>
<P> srand(time(0));</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2> for</FONT></FONT><FONT
size=2>(a=0;a<=9;a++)</P>
<P> {</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2> for</FONT></FONT><FONT
size=2>(b=0;b<=9;b++)</P>
<P> {</P>
<P> cont=0;</P>
<P> n=rand()%10;
</FONT><FONT color=#008000 size=2><FONT color=#008000 size=2>//Generamos los
nmeros al azar...</P></FONT></FONT><FONT size=2>
<P> matriz[a][b]=n;</P>
<P> printf(</FONT><FONT
color=#a31515 size=2><FONT color=#a31515 size=2>" %d "</FONT></FONT><FONT
size=2>,matriz[a][b]);</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2> for</FONT></FONT><FONT
size=2>(c=2;(c<matriz[a][b])&& !cont ;c++)</P>
<P> {</P>
<P> r=matriz[a][b]%c;</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2> if</FONT></FONT><FONT
size=2>(r==0) </P>
<P> cont=1;</P>
<P> }</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2> if</FONT></FONT><FONT
size=2>(!cont) </P>
<P> cont2++;</P>
<P> }</P>
<P> printf(</FONT><FONT
color=#a31515 size=2><FONT color=#a31515 size=2>"\n\t"</FONT></FONT><FONT
size=2>);</P>
<P> }</P>
<P> printf(</FONT><FONT color=#a31515 size=2><FONT
color=#a31515 size=2>"\n\n\n\tLos primos son: %d"</FONT></FONT><FONT
size=2>,cont2);</P>
<P> getchar();</P>
<P></FONT><FONT color=#0000ff size=2><FONT color=#0000ff
size=2> return</FONT></FONT><FONT size=2> 0;</FONT></P>
<P><FONT size=2>}</P></FONT></DIV>
<DIV style="FONT: 10pt Tahoma">
<DIV><BR></DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A
title="mailto:cristian.vj23@hotmail.com
CTRL + clic para seguir el vínculo"
href="mailto:cristian.vj23@hotmail.com">tACho XD Cristian Villota</A> </DIV>
<DIV><B>Sent:</B> Monday, March 01, 2010 2:03 PM</DIV>
<DIV><B>To:</B> <A
title="mailto:cconclase@listas.conclase.net
CTRL + clic para seguir el vínculo"
href="mailto:cconclase@listas.conclase.net">C++ con clase</A> </DIV>
<DIV><B>Subject:</B> [C con Clase] Números primos en una
matriz</DIV></DIV></DIV>
<DIV><BR></DIV>Hola a todos:
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV>Estoy intentando contar los números primos que se encuentran en una matriz
de [10][10]; pero cada vez que ejecuto el programa me indica un cero y parece
que no los cuenta. El código que estoy utilizando es el siguiente; si alguien
capta el error le agradecería que me lo corrija:</DIV>
<DIV><BR></DIV>
<DIV>
<DIV><BR></DIV>
<DIV>#include<stdio.h></DIV>
<DIV>#include<conio.h></DIV>
<DIV>#include<stdlib.h></DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV>void main()</DIV>
<DIV>{</DIV>
<DIV><BR></DIV>
<DIV> clrscr();</DIV>
<DIV><BR></DIV>
<DIV> int
a,b,c,d,n,v,cont=0,j,k,r,matriz[10][10],vector[10],cont2=0;</DIV>
<DIV><BR></DIV>
<DIV> printf("\n\n\t");</DIV>
<DIV><BR></DIV>
<DIV> //Generamos la matriz....</DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV> for(a=0;a<=9;a++)</DIV>
<DIV> {</DIV>
<DIV> for(b=0;b<=9;b++)</DIV>
<DIV> {</DIV>
<DIV> n=rand()%10; //Generamos los
n£meros al azar...</DIV>
<DIV><BR></DIV>
<DIV> matriz[a][b]=n;</DIV>
<DIV> printf(" %d ",matriz[a][b]);</DIV>
<DIV><BR></DIV>
<DIV> for(c=1;c<=matriz[a][b];c++)</DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=Apple-tab-span></SPAN>{</DIV>
<DIV><SPAN style="WHITE-SPACE: pre"
class=Apple-tab-span></SPAN>r=matriz[a][b]%c;</DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=Apple-tab-span></SPAN>if(r==0)</DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=Apple-tab-span></SPAN> {</DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=Apple-tab-span></SPAN>
cont=cont+1;</DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=Apple-tab-span></SPAN> }</DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=Apple-tab-span></SPAN>}</DIV>
<DIV> if(cont<=2)</DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=Apple-tab-span></SPAN>{</DIV>
<DIV><SPAN style="WHITE-SPACE: pre"
class=Apple-tab-span></SPAN>cont2=cont2+1;</DIV>
<DIV><SPAN style="WHITE-SPACE: pre" class=Apple-tab-span></SPAN>}</DIV>
<DIV><BR></DIV>
<DIV> }</DIV>
<DIV><BR></DIV>
<DIV> printf("\n\t");</DIV>
<DIV> }</DIV>
<DIV><BR></DIV>
<DIV> printf("\n\n\n\tLos primos son: %d",cont2);</DIV>
<DIV><BR></DIV>
<DIV>getch();</DIV>
<DIV><BR></DIV>
<DIV>}</DIV>
<DIV><BR></DIV>
<DIV><BR></DIV></DIV>
<DIV> </DIV><BR>
<HR>
Invite your mail contacts to join your friends list with Windows Live Spaces.
It's easy! <A
href="http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us"
target=_new>Try it!</A>
<P>
<HR>
<P></P>_______________________________________________<BR>Lista de correo
Cconclase
Cconclase@listas.conclase.net<BR>http://listas.conclase.net/mailman/listinfo/cconclase_listas.conclase.net<BR>Bajas:
http://listas.conclase.net/index.php?gid=2&mnu=FAQ</BODY></HTML>