THIS IS D PROGRAM TO GENERATE LUCKY NUMBERS OUT OF A GIVEN NUMBERS FIRSTLY SUPPOSE CONSIDER 10 ITEMS 1 2 3 4 5 6 7 8 9 10 FIRSTLY EACH 2ND ELEMENT IS DELETED THEN WE GET 1 3 5 7 9 THEN EACH 3RD ELEMENT IS DELETED 1 3 7 9 THEN EACH 4TH ELEMENT WILL BE DELETED THEN WE GET 1 3 7 NOW EACH 5TH ELEMENT IS DELETED AS THERE IS NO 5TH ITEM WE GET 1 3 7 THE ABOVE NOS 1 3 7 ARE CALLED LUCKY NOS THIS GIVEN PROGRAM IS WRITTEN IN C SO TRY IT ONCE CODE:C Code: #include"stdio.h" #include"conio.h" void main() { int i,k=0,p=2,t=0,n;int a[100]; printf("enter the size of the array:\n"); scanf("%d",&n); printf("enter the elements of the array\n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf(" The Sequence Of Lucky Nos Per Step Are:\n"); for(i=0;i<n;i++) { printf("%d",a[i]); printf("\t"); } while(1) { t=0; for(i=0;i<n;i++) { if(a[i]!=32767) { k++; if(k==p) { a[i]=32767;t++; k=0; } } } p++;k=0; if(t==0) { break; } printf("\n"); for(i=0;i<n;i++) { if(a[i]!=32767) { printf("%d ",a[i]); printf("\t"); } } printf("\n"); } getch(); }
Moved it to forum because for it to be an Article I expect a bit more details like what is Lucky Numbers and stuff like that