1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

Generation of lucky nos from a given list of nos.

Discussion in 'C' started by amanbaua, Sep 3, 2009.

  1. amanbaua

    amanbaua New Member

    Joined:
    Aug 23, 2009
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    0
    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();
     }
     
    Last edited by a moderator: Sep 4, 2009
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,276
    Likes Received:
    364
    Trophy Points:
    83
    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
     

Share This Page