Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <conio.h>
- int soNgTo(int n)
- {
- int i,kt;
- for(i=2; i<=sqrt(n); i++)
- {
- if(n%i==0) break;
- }
- if(i>sqrt(n)) kt=1;
- else kt=0;
- if(n<2) kt=0;
- return kt;
- }
- int sapxep(int a[],int N)
- {
- int t,i,j;
- for(i=0;i<N-1;i++)
- for(j=i+1;j<N;j++)
- if(a[i]<a[j])
- {
- t=a[i];
- a[i]=a[j];
- a[j]=t;
- }
- printf("\nDay so tu lon den be:\n");
- for(i=0; i<N; i++)
- printf("%d ",a[i]);
- }
- int main()
- {
- int i,t,n,SL;
- i=0;
- int a[50];
- system ("color green");
- printf("NHAP MANG CHI GOM CAC SO NGUYEN TO\n");
- printf("nhap so luong: "); scanf("%d",&SL);
- while(i<SL)
- {
- printf("nhap so thu %d: ",i+1);
- scanf("%d",&a[i]);
- t=a[i];
- if(soNgTo(t)==1) i++;
- else printf("nhap sai! nhap lai so thu %d\n",i+1);
- }
- for(int i=0;i<SL;i++)
- printf("%d ",a[i]);
- sapxep(a,SL);
- _getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement