SHARE
TWEET

Untitled

a guest May 27th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4.  
  5. int main()
  6. {
  7.  
  8.     int mas[15] = {1,45,2,56,23,65,322,65,1,32,5,23,6,78,65},search2;
  9.     scanf("%d",&search2);
  10.  
  11.    
  12.     for (int i = 0; i < 15; i++)
  13.     {
  14.         if(search2 == mas[i])
  15.         {
  16.             printf("IndexOf: %d \n",i+1);
  17.             break;
  18.  
  19.         }
  20.          if(i == 14 && search2 != mas[i])
  21.         {
  22.             printf("IndexOf: -1\n");
  23.         }
  24.     }
  25.  
  26.  
  27.    
  28.  
  29.       for (int i = 14; i > -1; i--)
  30.        {
  31.            if (search2 == mas[i])
  32.            {
  33.                printf("LastIndexOf: %d ",abs(i+1-15));
  34.                break;
  35.  
  36.            }
  37.  
  38.          else if(i == 0 && search2 != mas[i])
  39.         {
  40.             printf("LastIndexOf: -1\n");
  41.         }
  42.        }
  43.  
  44.     return 0;
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top