Skip to content

Instantly share code, notes, and snippets.

@chukitow
Last active December 30, 2015 10:59
Show Gist options
  • Select an option

  • Save chukitow/7819270 to your computer and use it in GitHub Desktop.

Select an option

Save chukitow/7819270 to your computer and use it in GitHub Desktop.
Examen de humberto, leer numeros guardados en un archivo de texto y determinar cuantos numeros terminan con 0,1,2,3,4,5,6,7,8,9
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream archivo("C:\\Users\\Ivan Velasquez Rios\\Desktop\\examen.txt", ios::in);
char numeros[20];
int num, sum=0;
int contador[10] = {0};
if(!archivo)
{
exit(0);
}
else
{
while(!archivo.eof())
{
archivo>>numeros;
for(int i=0; i<20;i++)
{
if(numeros[i]=='\0')
{
num = numeros[i-1];
}
}
num = num - 48;
contador[num]++;
sum++;
}
}
for(int i=0;i<10;i++)
{
cout<<"El numero "<<i<<" salio " << contador[i] <<" Tantas veces"<<endl;
}
cout<<"Total de numeros "<<sum <<endl;
cin.get();
cin.get();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment