Advertisement
Abelsor

S3_Ejercicio_1

Feb 23rd, 2023 (edited)
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4.  
  5. int main(){
  6.     float nf;
  7.     cin>>nf; // no modifique la instrucción de lectura
  8.    
  9.     // Case 1
  10.     if(nf<0 or nf != int(nf)){
  11.         cout<<"Error, el número ingresado debe ser entero y positivo";
  12.     }
  13.    
  14.     // Case 2
  15.     else{
  16.         int acumulador = 0;
  17.        
  18.         for(int i=1 ; i<=nf ; i++){
  19.             acumulador += i;  
  20.         }
  21.        
  22.         cout<<acumulador;  
  23.     }
  24.    
  25.     return 0; // no utilize system(pause)
  26.        
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement