Showing posts with label Microsoft. Show all posts
Showing posts with label Microsoft. Show all posts

Tuesday 2 October 2012

Re-arrange the odd/even to odd/even places





#include<stdio.h>

void Swap (int A[], int i, int j)
{
    int temp = A[i];
    A[i]=A[j];
    A[j]=temp;
}

int main()
{
    int A[] = {3,1,4,5,7,6,10,8};
    int i=0,j=1,n;
    n=sizeof(A)/sizeof(int);
    while(i<n)
    {
        while(i<n && A[i]%2 == 0)
            i+=2;
        while(j<n && A[j]%2 == 1)
            j+=2;
        if(i<n && j<n)
            Swap(A,i,j);
    }// end of while

    for(i=0;i<n;i++)
        printf(" %d",A[i]);

return 0;
}

Let me know your thoughts

Wednesday 4 July 2012

WAP to return numbered index if input is excel sheet column header name. e.g excel sheet column headers are A, B, C , D ... Z, AA, AB...AZ, BA,, etc if Input is D , output should be 4 and for AA output should be 27

// TIME : O(n)

#include<stdio.h> #include<string.h> int main() { int i=0,l,x,index=0; char S[5]; printf("Enter Column header : "); gets(S); l=strlen(S); while(i<l) { x=S[i++]-'A'+1; index=index*26+x; } printf("%d",index); return 0; }