Advertisement
Guest User

q1-mivhan-sof-sem

a guest
Feb 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 7
  3.  
  4. /// 1,2,3, 0 2,4,6, דוגמא///
  5.  
  6. void input_f(int v[N])
  7. {
  8.     int i;
  9.  
  10.     for (i = 0 ; i<N; i++ )
  11.     {
  12.         scanf("%d",&v[i]);
  13.     }
  14. }
  15.  
  16.  /*מקרא */
  17. ///counter1 = מונה ראשון
  18. ///counter2 = מונה שני
  19. /// total_counter = מונה סופי שנכנס בו המונה הראשון או השני ועליו מצביע הפוינטר שמחזיר את הכמות
  20. /// currentIndex = מיקום נוכחי
  21. /// newIndex = מיקום חדש
  22.  
  23. void up_max_seq_f(int v[N], int *p_totalcounter, int *p_index)
  24.  
  25. {
  26.  
  27.     int i, j, counter1 = 0, counter2 = 0, total_counter=0, currentIndex = 0 , newIndex=0;
  28.  
  29.     for (i = 0 ,j = 1; i < N , j < N ; i++ , j++)
  30.     {
  31.         currentIndex = i;
  32.  
  33.         if(v[i] < v[j])
  34.         {
  35.             counter1++;
  36.         }
  37.  
  38.          else
  39.            {
  40.              counter2++;
  41.  
  42.            }
  43.  
  44.  
  45.     if(counter1 < counter2)
  46.     {
  47.         total_counter = counter2;
  48.         newIndex = counter2 - j;
  49.     }
  50.     else
  51.      {
  52.         total_counter = counter1;
  53.         newIndex = counter1 - j;
  54.      }
  55.  
  56.  
  57.     }
  58.  
  59.  
  60.     *p_index= newIndex;
  61.     *p_totalcounter = total_counter;
  62.  
  63.  
  64. }
  65. void main()
  66. {
  67.  
  68.     int v[N], i, j, counter1 = 0, counter2 = 0, total_counter = 0, currentIndex = 0, newIndex = 0;
  69.  
  70.     puts("enter numbers \n");
  71.     input_f(v);
  72.     up_max_seq_f(v,&total_counter , &newIndex);
  73.     printf("the series start at index = %d \n total numbers on this series = %d \n", newIndex , total_counter);
  74.  
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement