Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include "iostream"
  2. using namespace std;
  3.  
  4. int f1(int *a, short i)
  5. {
  6. int g=0;
  7. int k=a[0];
  8. for(short j=1;j<i;j++)
  9. if(k<a[j])
  10. {
  11. k=a[j];
  12. g=j;
  13. }
  14. return g;
  15. }
  16. void f2(int *a, short i)
  17. {
  18. int k1=0,k2=0;
  19. short j=0;
  20. for(j=0;j<i;j++)
  21. if(a[j]==0)
  22. {k1=j;goto end1;}
  23. cout<<"\nNo \"0\" elements.";goto end;
  24. end1:
  25. for(j=k1+1;j<i;j++)
  26. if(a[j]==0)
  27. {k2=j;goto end2;}
  28. end2:
  29. if((k1+1)<k2)
  30. {
  31. k1+=1;int s=1;
  32. for(;k1<k2;k1++)
  33. s=s*a[k1];
  34. cout<<"\ns="<<s;
  35. }
  36. else
  37. cout<<"\nOnly 1 \"0\" element, or 2 \"0\" elements on adjacent positions";end:
  38. if(i%2==0)
  39. for(int h,j=1;j<i/2;j+=2)
  40. {
  41. h=a[j];
  42. a[j]=a[i-1-j];
  43. a[i-1-j]=h;
  44. }
  45. else
  46. for(int h,j=1;j<i/2+1;j+=2)
  47. {
  48. h=a[j];
  49. a[j]=a[i-j];
  50. a[i-j]=h;
  51. };
  52. end4:
  53. cout<<'\n';
  54. for(j=0;j<i;j++)
  55. {
  56. cout<<' '<<a[j];
  57. };
  58.  
  59. }
  60.  
  61. void main()
  62. {
  63. int i;
  64. cout<<"\nEnter size. Under 100:";
  65. again:
  66. cin>>i;
  67. if(i>100||i<=0)
  68. {cout<<"\nError. Try again.";goto again;}
  69. int a[100];
  70. for(int j=0;j<i;j++)
  71. cin>>a[j];
  72. cout<<'\n'<<f1(a,i);
  73. f2(a,i);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement