Monday, March 1, 2010

NUMER REARRANGEMENT CODE

INPUT          : -23 19 12 -11 56 -1 8 9 -45 -9


OUTPUT        : -23 -11 -1 -45 -9 19 12 56 8 9
FILENAME      :  NumberAlighnment_urname.cpp
POSTER       :  Vineeth


SOLUTIONS:

PROVIDED BY AVINASH





#include"stdio.h"
#define MAX 10
void MyFunction(int [],int iNumNegativeCount);
int main()
{
    int aNumbers[10] = {0,},iCount = 0;
    printf("Enter 10 numbers:");
    for(iCount=0; iCount
    scanf("%d",&aNumbers[iCount]);
    MyFunction(aNumbers, 0);
    printf("\nSortednumbers are:");
    for(iCount=0; iCount
    printf("%d ",aNumbers[iCount]);
    return 0;

}
   void MyFunction(int array[],int iNumNegativeCount)
    {
        static int iNumCount = 0;
        int iTemp=0;
        int iCount=0;
        if(iNumCount < MAX)
        {
           if(array[iNumCount]<0)
           {
                iTemp = array[iNumCount];
               if(iNumCount == iNumNegativeCount)
                array[iNumNegativeCount++] = iTemp;
               else
               {
                 for(iCount = iNumCount; iCount > iNumNegativeCount; iCount--)
                   array[iCount] = array[iCount -1];              
                 array[iNumNegativeCount++] = iTemp;
                }
            }
                       
               iNumCount++;
               MyFunction(array,iNumNegativeCount);
        }
        else
            return ;
    }







1 comment:

Avinash Reddy K said...

#include"stdio.h"

#define MAX 10

void MyFunction(int [],int iNumNegativeCount);

int main()

{

int aNumbers[10] = {0,},iCount = 0;

printf("Enter 10 numbers:");

for(iCount=0; iCount iNumNegativeCount; iCount--)//Traverse –ve numbers to leftside

array[iCount] = array[iCount -1];

array[iNumNegativeCount++] = iTemp;

}

}



iNumCount++;

MyFunction(array,iNumNegativeCount);

}

else

return ;

}

counter