Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define N 7
- /// 1,2,3, 0 2,4,6, דוגמא///
- void input_f(int v[N])
- {
- int i;
- for (i = 0 ; i<N; i++ )
- {
- scanf("%d",&v[i]);
- }
- }
- /*מקרא */
- ///counter1 = מונה ראשון
- ///counter2 = מונה שני
- /// total_counter = מונה סופי שנכנס בו המונה הראשון או השני ועליו מצביע הפוינטר שמחזיר את הכמות
- /// currentIndex = מיקום נוכחי
- /// newIndex = מיקום חדש
- void up_max_seq_f(int v[N], int *p_totalcounter, int *p_index)
- {
- int i, j, counter1 = 0, counter2 = 0, total_counter=0, currentIndex = 0 , newIndex=0;
- for (i = 0 ,j = 1; i < N , j < N ; i++ , j++)
- {
- currentIndex = i;
- if(v[i] < v[j])
- {
- counter1++;
- }
- else
- {
- counter2++;
- }
- if(counter1 < counter2)
- {
- total_counter = counter2;
- newIndex = counter2 - j;
- }
- else
- {
- total_counter = counter1;
- newIndex = counter1 - j;
- }
- }
- *p_index= newIndex;
- *p_totalcounter = total_counter;
- }
- void main()
- {
- int v[N], i, j, counter1 = 0, counter2 = 0, total_counter = 0, currentIndex = 0, newIndex = 0;
- puts("enter numbers \n");
- input_f(v);
- up_max_seq_f(v,&total_counter , &newIndex);
- printf("the series start at index = %d \n total numbers on this series = %d \n", newIndex , total_counter);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement