fork 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 15240KB
stdin
3 8 9 9
stdout
Enter number of Integer in array
Enter element of array No intermediate element present in between these 8 & 9 elements
No intermediate element present in between these 9 & 9 elements