Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- //Câu a :
- printf("Cau a :\n");
- int n = 0;
- do
- {
- printf("Nhap n = ");
- scanf("%d", &n);
- if(n <= 0)
- printf("Dieu kien : n > 0. Hay nhap lai.\n");
- }while(n <= 0);
- //Câu b:
- printf("\nCau b :\n");
- int a[1000];
- int i = 0;
- for(i = 0; i < n; i++)
- {
- printf("a[%d] = ", i);
- scanf("%d", &a[i]);
- }
- //Câu c:
- printf("\nCau c :\n");
- int flag = 0;
- for(i = 0; i < n; i++)
- {
- if((int)sqrt(a[i]) == sqrt(a[i]))
- {
- flag = 1;
- printf("%5d", a[i]);
- }
- }
- if(!flag)
- printf("Khong tim thay so nao");
- //Câu d:
- printf("\nCau d :\n");
- flag = 0;
- for(i = 0; i < n; i++)
- {
- if((int)sqrt(a[i]) == sqrt(a[i]) && !(a[i] % 2))
- {
- flag = 1;
- printf("%5d", a[i]);
- }
- }
- if(!flag)
- printf("Khong tim thay so nao");
- //Câu e:
- printf("\nCau e :\n");
- int j;
- flag = 0;
- for(i = 0; i < n - 1; i++)
- {
- for(j = i + 1; j < n; j++)
- {
- if(a[i] > a[j])
- {
- int temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- }
- }
- }
- for(i = 0; i < n; i++)
- {
- if(a[i] % 2)
- {
- flag = 1;
- printf("%5d", a[i]);
- }
- }
- if(!flag)
- printf("Khong tim thay so nao");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement