Skip to content

Instantly share code, notes, and snippets.

@pizenblues
Last active August 29, 2015 14:08
Show Gist options
  • Save pizenblues/47a1e2d7d47f7171d208 to your computer and use it in GitHub Desktop.
Save pizenblues/47a1e2d7d47f7171d208 to your computer and use it in GitHub Desktop.
#include<iostream.h>
#include <stdio.h>
using namespace std;
template <class T>
void read_input(T &var){
while(! (cin>>var) ){
printf(" \t \t ingrese un numero: ");
cin.clear();
cin.ignore(256, '\n');
};
}
template <class T>
void read_char(T *var){
while(! (std::cin>>var) ){
// optional generic message, like 'wrong format, reinput'
std::cin.clear();
std::cin.ignore(256, '\n');
};
}
int main(){
char opc;
int tamano, multiple;
int fila = 1, columna = 1;
printf("\n\t cantidad de vertices ");
read_input(tamano);
int matriz[tamano][tamano];
for(int i =0; i<tamano; i++)
for(int j = i; j<tamano; j++){
fila = fila + i;
columna = columna + j;
printf("\n el vertice %i es adyacente al vertice %i (s/n): ", fila, columna);
read_char(opc);
if(opc == 's'){
printf(" \n\t es multiple? (s/n): ");
cin>>opc;
if(opc == 's'){
cout<<"\n\t cuantas veces?: ";
cin>>multiple;
matriz[i][j] = multiple;
matriz[j][i] = multiple;
}else{
matriz[i][j] = 1;
matriz[j][i] = 1;
}
}else{
matriz[i][j] = 0;
matriz[j][i] = 0;
}
fila = 1;
columna = 1;
}
system("cls");
cout<<endl<<endl;
for(int i=0; i<tamano; i++){
for(int j=0; j<tamano; j++){
cout<<"\t"<<matriz[i][j];
}
cout<<endl;
}
printf("menu");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment