Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- {
- int *a;
- int N;
- printf("\nVvedi kol elementov v masive\n");
- scanf("%d",&N);
- a = (int*)malloc(N*sizeof(int));
- int i;
- int cc = 0;
- int cs;
- printf("Skolko prostih cisel vivesti?\n");
- scanf("%d",&cs);
- for(i=0; i<N; i++){
- a[i] = i;
- }
- a[1]=0;
- int s;
- int j;
- for(s=0; s<N; s++){
- if(a[s]!=0)
- {
- for(j=s*2; j<N; j+=s)
- {
- a[j]=0;
- }
- }
- }
- printf("==========================\n");
- for(i=0; i<N; i++){
- if(a[i]!=0)
- {
- cc++;
- printf("El %d = %d\n",cc,a[i]);
- if(cc==cs)
- {
- break;
- }
- }
- }
- if(cc!=cs)
- {
- printf("Bolse cisel netu");
- }
- free(a);
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement