fork download
  1. using namespace std;
  2. #include<iostream>
  3.  
  4. int main()
  5. {
  6. double s=1,i; int n;
  7.  
  8. cout<<"Enter n(n=2k):";
  9. cin>>n;
  10. if(n%2>0)
  11. {
  12. cout<<"the number you entered is odd";
  13. cin>>n;
  14. }
  15. else
  16. {
  17. for(i=2;i<=n;i+=2)
  18. {
  19. s+=(i+1)/i;
  20. }
  21. cout<<"sum of them="<<s;
  22. }
  23.  
  24. }
Success #stdin #stdout 0s 3300KB
stdin
7
stdout
Enter n(n=2k):the number you entered is odd