Advertisement
huutho_96

min max

Nov 26th, 2016
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<iostream>
  4. using namespace std;
  5. int a[100];
  6. void main()
  7. {
  8.     int i,n,max,min;
  9.     cout<<"Nhap vao so phan tu cua mang: "<<endl;
  10.     cin>>n;
  11.     for (i=0; i < n; i++)
  12.     {
  13.         cout << "Nhap vao phan tu thu " << i + 1 << ": ";
  14.         cin >> a[i];
  15.     }
  16.    
  17.     max=a[0];
  18.     min=a[0];
  19.     for (i=0; i < n; i++ )
  20.     {
  21.         if (min > a[i]) min = a[i];
  22.         if (max < a[i]) max = a[i];
  23.     }
  24.     cout << " Phan tu nho nhat la: " << min << endl;
  25.     cout << " Phan tu lon nhat la: " << max << endl;
  26.     getch();
  27. }
  28.  
  29.  
  30. #include<stdio.h>
  31. #include<conio.h>
  32.  
  33. int a[100];
  34. void main()
  35. {
  36.     int i, n, max, min;
  37.     printf("nhap so phan tu cua mang: ");
  38.     scanf("%d", &n);
  39.     for (i = 0; i < n; i++)
  40.     {
  41.         printf("nhap phan tu thu %d: ", i + 1);
  42.         scanf("%d", &a[i]);
  43.     }
  44.     max = a[0]; min = a[0];
  45.     for (i = 0; i < n; i++)
  46.     {
  47.         if (min > a[i])min = a[i];
  48.         if (max < a[i])max = a[i];
  49.     }
  50.     printf("phan tu nho nhat la: %d\n", min);
  51.     printf("phan tu lon nhat la: %d\n", max);
  52.     getch();
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement