Untitled
unknown
plain_text
4 years ago
1.2 kB
3
Indexable
//11. Hacer un programa que permita contar número de valores negativos, positivos y ceros que hay en un vector. #include <iostream> #include <stdio.h> #include <stdlib.h> #include <time.h> using namespace std; void leerVector(float vec[], int n){ int i; for(i=0;i<n; i++){ cout<<"Vec["<<i<<"] : "; cin>>vec[i]; } } void imprimaVector(float vec[], int n){ int i; cout << endl<<"El vector es --->>"<<endl; for(i=0;i<n; i++){ cout<<vec[i]<<" " ; } } void PosNegCer(float vec[], int n){ int pos = 0, neg = 0, cer = 0; for (int i = 0; i < n ;i++){ if (vec[i] < 0){ neg++; } if (vec[i] == 0){ cer++; } if (vec[i] > 0){ pos++; } } cout<<"El total de elementos positivos es: "<< pos << endl; cout<<"El total de elementos negativos es: "<< neg << endl; cout<<"El total de elementos igual a cero es de: "<< cer; } int main(){ int n = 0; float resul, vec[100]; cout<<"\nTamaño del vector: "; cin>>n; leerVector(vec, n); imprimaVector(vec, n); PosNegCer(vec,n); return 0; }
Editor is loading...