Advertisement
Dani_info

nr pare dintr-un interval_dani

Oct 15th, 2017
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int a, b, n;
  8. cout<<"Introduceti capetele intervalului[a,b]:";
  9. cin>>a>>b;
  10. n=b-a+1;
  11. if(n%2==0)
  12. cout<<"Exista "<<n/2<<" nr pare in inerval";
  13. else
  14. if(a%2==0)
  15. cout<<"Exista "<<(n+1)/2<<" nr pare in inerval";
  16. else
  17. cout<<"Exista "<<(n-1)/2<<" nr pare in inerval";
  18.  
  19. return 0;
Advertisement
RAW Paste Data Copied
Advertisement