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"<<endl;
  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 4488KB
stdin
3 8 9 9
stdout
Enter number of Integer in array 
Enter elements of array 
No intermediate element in between these 8 & 9 elements
No intermediate element in between these 9 & 9 elements