toanalien

in array

Dec 3rd, 2014
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. int i, k, tong, a[100];
  8.  
  9. void main()
  10. {
  11.     printf("Nhap so phan tu cua mang: ");
  12.     scanf("%d", &i);
  13.     for (int j = 1; j <= i; j++)
  14.     {
  15.         printf("a[%d] = ", j);
  16.         scanf("%d", &a[j]);
  17.     }
  18.  
  19.     printf("Nhap gia tri can kiem tra k = ");
  20.     scanf("%d", &k);
  21.  
  22.     for (int j = 1; j <= i; j++)
  23.     {
  24.         if (a[j] == k)
  25.         {
  26.             printf("k = %d thuoc phan tu trong mang", k);
  27.             _getch();
  28.             return;
  29.         }
  30.     }
  31.     printf("k = %d khong thuoc phan tu trong mang", k);
  32.     _getch();
  33. }
Add Comment
Please, Sign In to add comment