Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Hacer un programa que permita ingresar una lista de números positivos, negativos o cero hasta que se ingrese
- el 5º número par.
- Calcular e informar:
- La cantidad de ternas de números negativos ingresados de manera consecutiva.
- Ejemplo A: 4, -1, -4, -5, 10, -3, -5, 7, -5, -3, -6, 10 → Cantidad de ternas: 2 */
- // Comentarios:
- #include <iostream>
- using namespace std;
- int main(void){
- int n;
- int primerneg,segundoneg,tercerneg;
- int contpares=0;
- int contternas=0;
- int esneg=0;
- do
- {
- cout<< " Ingrese un numero: "<<endl;
- cin>>n;
- if(n%2==0)
- {
- contpares++;
- }
- if(n<0)
- {
- esneg++;
- if( esneg==3 )
- {
- contternas++;
- }
- }
- else
- {
- esneg=0;
- }
- }
- while(contpares<5);
- /* else{
- if(n<0 && esneg>2 && contnumeros>=3)
- {
- esneg++;
- contternas++;
- }
- } */
- cout<<"La cantidad de ternas de numeros negativos ingresados de manera consecutiva es: "<<contternas<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment