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