fork download
  1. #include <iostream>
  2. using namespace std;
  3. main()
  4. {
  5. int n;
  6. cout<<"Enter number of Integer in array "<<endl;
  7. cin>>n;
  8. int num[n];
  9. cout<<"Enter elements of array "<<endl;
  10. for(int p=0;p<n;p++)
  11. cin>>num[p];
  12. for(int k=0;k<n-1;k++)
  13. {
  14. if((num[k]-num[k+1]==1) || (num[k+1]-num[k]==1) || (num[k]==num[k+1]))
  15. {
  16. cout<<"No intermediate element in between these "<<num[k]<<" & "<<num[k+1]<<" elements";
  17. }
  18. else if(num[k]<num[k+1])
  19. {
  20. cout<<"Element between "<<num[k]<<" and "<<num[k+1]<<" is/are ";
  21. for(int a=num[k];a<num[k+1]-1;)
  22. {
  23. cout<<++a<<" ";
  24. }
  25. cout<<endl;
  26. }
  27. else if(num[k]>num[k+1])
  28. {
  29. cout<<"Element between "<<num[k]<<" and "<<num[k+1]<<" is/are ";
  30. for(int a=num[k+1];a<num[k]-1;)
  31. {
  32. cout<<++a<<" ";
  33. }
  34. cout<<endl;
  35. }
  36. }
  37. }
Success #stdin #stdout 0s 4392KB
stdin
4 2 6 8 3
stdout
Enter number of Integer in array 
Enter elements of array 
Element between 2 and 6 is/are 3 4 5 
Element between 6 and 8 is/are 7 
Element between 8 and 3 is/are 4 5 6 7