C/Visual C - Explicación

 
Vista:

Explicación

Publicado por Estudiante (1 intervención) el 03/04/2015 04:43:40
Necesito que por favor me expliquen cada linea después de "Declarar Variables". necesito hacerlo con los codios: Cout y Cin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <ctype.h> // isdigit 
#include <stdlib.h> // atoi 
#include <string.h> // strlen 
#include <stdio.h> // printf, fgets, stdin, BUFSIZ 
 
using namespace std;
 
int main()
{
//Declarar Variables 
int number;
unsigned n;
char buffer[BUFSIZ];
bool found_nondigit, valid;
 
//Proceso 
valid = false;
while (!valid) {
printf ( "Enter an integer: " );
if (fgets (buffer, sizeof buffer, stdin) != NULL){
buffer[strlen(buffer)-1] = \0 ;
found_nondigit = false;
if (strlen(buffer) == 0) // comprueba si el usuario ha pulsado "Intro" sin introducir una entrada 
found_nondigit = true;
for (n=0; n<strlen(buffer); n++)
if (!isdigit(buffer[n]))
found_nondigit = true;
if (!found_nondigit){
number = atoi(buffer); // convierte la entrada en un entero cuando se ha validado 
printf ("%d\n", number);
valid = true;}
else
printf ( "Error: Invalid input\n" );
}
}
return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de daniel

Explicación

Publicado por daniel (4 intervenciones) el 10/04/2015 09:53:32
gracias......me diste una ayuda........modifique el metodo 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <stdio.h>
 
int main()
{
 int arrayPrincipal[10]={1,2,3,7,4,1,7,1,2,1};
int aux[10];
int pos,size=10,contador;
for(int i=0;i<size;i++){
pos=0;
contador=0;
for(int j=0;j<size;j++){
if(arrayPrincipal[i] != arrayPrincipal[j]){
aux[pos++]=arrayPrincipal[j];
}else{
contador++;
}
}
cout<<"el numero "<<arrayPrincipal[i]<< " se repite "<<contador<<"\n";
size-=contador;
for(int u=0;u<size;u++){
arrayPrincipal[u]=aux[u];
}
i--;
}
   return 0;
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar