ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
1. Duplicate the even numbers. -1

Sample I/O

Array1:- 4,2,24,3,22

Updated Array:- 4,4,2,2,24,24,3,22,22
2. Reverse the array in a region - 1

Sample I/O

Array1:- 4,2,24,3,22,41,21

Enter Region:- 2,5

Update Array:-4,41,22,3,24,2,21


3. Store first the even digits in an array and then odd
digits in same array -2

Sample I/O

Array1:- 4,2,24,3,22,41,21

Array 2:- 4,2,2,4,2,2,4,2,3,1,1
4. Store the count of the digits in all numbers in an array
and print the count. -2

Sample I/O

Array1:- 4,2,9,3,7,41,28

Array 2:- 0,1,1,1,2,0,0,1,1,1

1-1;2-1;3-1;4-2;7-1;8-1;9-1
5. Store all palindrome numbers in to another array -2

Sample I/O

Array1:- 4,22,9,313,7,141,28

Array 2:- 4,22,9,313,141


6. Arrange the array in such a way that odd numbers come
first and then even numbers -1

Sample I/O

Array1:- 4,22,9,313,7,141,28

Update Array1:- 9,313,7,141,4,22,28
7. Store into another array by inserting it in the right
place - 2

Sample I/O

Array1:- 4,22,9,313,7,141,28

Array2:- 4 /4,22 /4,9,22 /4,9,22 ,313 /4,7,9,22 ,313
/4,7,9,22 ,141,313 /

4,7,9,22,28 ,141,313
8. Merge two sorted arrays in a sorted fashion -  3

Sample I/O

Array 1:- 3,6,7,9,11,16

Array 2:- 1,2,5,7,20

Array 3:- 1,2,3,5,6,7,9,11,16,20

9. Upadte the array so that an array element is followed by
its revere - 1

Sample I/O

Array 1:- 13,63,74,9,11,16

Updated Array 1:- 13,31,63,36,74,47,9,9,11,11,16,16

10.Spread the digits of the array in the same array. -1

Sample I/O

Array 1:- 13,63,74,9,11,16

Updated Array 1:-1,3,6,3,74,9,1,1,1,6

11.Shift the boundary of array to have only 2 digit numbers.

Sample I/O

Array 1:- 139,643,74,9,101,126

Updated Array 1:- 13,96,43,74,91,11,26

12.Print the largest occuring digit in an array of N numbers.

Sample I/O

Array 1:- 13,63,74,9,11,16

1 occurs most.

 Question Submitted By :: Nithya
I also faced this Question!!     Rank Answer Posted By  
 
  Re: 1. Duplicate the even numbers. -1 Sample I/O Array1:- 4,2,24,3,22 Updated Array:- 4,4,2,2,24,24,3,22,22 2. Reverse the array in a region - 1 Sample I/O Array1:- 4,2,24,3,22,41,21 Enter Region:- 2,5 Update Array:-4,41,22,3,24,2,21 3. Store first the even digits in an array and then odd digits in same array -2 Sample I/O Array1:- 4,2,24,3,22,41,21 Array 2:- 4,2,2,4,2,2,4,2,3,1,1 4. Store the count of the digits in all numbers in an array and print the count. -2 Sample I/O Array1:- 4,2,9,3,7,41,28 Array 2:- 0,1,1,1,2,0,0,1,1,1 1-1;2-1;3-1;4-2;7-1;8-1;9-1 5. Store all palindrome numbers in to another array -2 Sample I/O Array1:- 4,22,9,313,7,141,28 Array 2:- 4,22,9,313,141 6. Arrange the array in such a way that odd numbers come first and then even numbers -1 Sample I/O Array1:- 4,22,9,313,7,141,28 Update Array1:- 9,313,7,141,4,22,28 7. Store into another array by inserting it in the right place - 2 Sample I/O Array1:- 4,22,9,313,7,141,28 Array2:- 4 /4,22 /4,9,22 /4,9,22 ,313 /4,7,9,22 ,313 /4,7,9,22 ,141,313 / 4,7,9,22,28 ,141,313 8. Merge two sorted arrays in a sorted fashion - 3 Sample I/O Array 1:- 3,6,7,9,11,16 Array 2:- 1,2,5,7,20 Array 3:- 1,2,3,5,6,7,9,11,16,20 9. Upadte the array so that an array element is followed by its revere - 1 Sample I/O Array 1:- 13,63,74,9,11,16 Updated Array 1:- 13,31,63,36,74,47,9,9,11,11,16,16 10.Spread the digits of the array in the same array. -1 Sample I/O Array 1:- 13,63,74,9,11,16 Updated Array 1:-1,3,6,3,74,9,1,1,1,6 11.Shift the boundary of array to have only 2 digit numbers. Sample I/O Array 1:- 139,643,74,9,101,126 Updated Array 1:- 13,96,43,74,91,11,26 12.Print the largest occuring digit in an array of N numbers. Sample I/O Array 1:- 13,63,74,9,11,16 1 occurs most.
Answer
# 1
1///Program to Duplicate the even numbers
#include<iostream>
using namespace std;
main()
{
        int n,i,j;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[2*n];
        if(n>0)
        {
        cout<<"Enter the numbers:";
        for(i=0;i<n;i++)
                cin>>a[i];
        cout<<"\n The original array is :";
        for(i=0;i<n;i++)
                cout<<"\t"<<a[i];
        for(i=0;i<=n;i++)
        {
               if(a[i]%2==0)
                {
                n++;
                for(j=n;j>i;j--)
                {
                        a[j]=a[j-1];
                }

                i++;
                a[i]=a[i-1];
                }
        }
        cout<<"\n The updated array is:";
        for(i=0;i<n-1;i++)
        {
                cout<<"\t"<<a[i];
        }
        }
        else
                cout<<"\n Invalid entry";
}
2.// Program to Reverse the array in the region
#include<iostream>
using namespace std;
main()
{
        int n,i,x,y,t;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[n];
        if(n>0)
        {
                cout<<"Enter the numbers:";
                for(i=1;i<=n;i++)
                        cin>>a[i];
                cout<<"Enter the positions for which the
array to be reversed from left to right:";
                cin>>x>>y;
                cout<<"\n the original array is:";
                for(i=0;i<n;i++)
                        cout<<a[i];
                if(x>y)
                {
                        t=x;
                        x=y;
                        y=t;
                }
                if(x<1 || y>n)
                        cout<<"\n Invalid entry";
                else
                {
                for(i=1;i<x;i++)
                {
                        cout<<"\t"<<a[i];
                }
                for(i=y;i>=x;i--)
                {
                        cout<<"\t"<<a[i];
                }
                for(i=y+1;i<=n;i++)
                {
                        cout<<"\t"<<a[i];
                }
                }
        }

        else
                cout<<"\n Invalid entry";
}

//Reverse the array in the region
#include<iostream>
using namespace std;
main()
{
        int n,i,x,y,t;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[n];
        if(n>0)
        {
                cout<<"Enter the numbers:";
                for(i=1;i<=n;i++)
                        cin>>a[i];
                cout<<"Enter the positions for which the
array to be reversed from left to right:";
                cin>>x>>y;
                cout<<"\n the original array is:";
                for(i=0;i<n;i++)
                        cout<<a[i];
                if(x>y)
                {
                        t=x;
                        x=y;
                        y=t;
                }
                if(x<1 || y>n)
                        cout<<"\n Invalid entry";
                else
                {
                for(i=1;i<x;i++)
                {
                        cout<<"\t"<<a[i];
                }
                for(i=y;i>=x;i--)
                {
                        cout<<"\t"<<a[i];
                }
                for(i=y+1;i<=n;i++)
                {
                        cout<<"\t"<<a[i];
                }
                }
        }

        else
                cout<<"\n Invalid entry";
}
3.//Store the count of the digits in all numbers in an array
and print the count
#include<iostream>
using namespace std;
main()
{
        int
n,i,d,count0=0,count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0,count8=0,count9=0;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[n];
        int count[10];
        if(n>0)
        {
                cout<<"\n Enter the numbers:\n";
                for(i=0;i<n;i++)
                        cin>>a[i];
                cout<<"\n The original array is:";
                        for(i=0;i<n;i++)
                                cout<<"\t"<<a[i];
                for(i=0;i<n;i++)
                {

                while(a[i]!=0)
                {

                        d=a[i]%10;
                        if(d==0)
                                count0++;
                        if(d==1)
                                count1++;
                        if(d==2)
                                count2++;
                        if(d==3)
                                count3++;
                        if(d==4)
                                count4++;
                        if(d==5)
                                count5++;
                        if(d==6)
                                count6++;
                        if(d==7)
                                count7++;
                        if(d==8)
                                count8++;
                        if(d==9)
                                count9++;
                        a[i]=a[i]/10;
                }
                }
                count[0]=count0;
                count[1]=count1;
                count[2]=count2;
                count[3]=count3;
                count[4]=count4;
                count[5]=count5;
                count[6]=count6;
                count[7]=count7;
                count[8]=count8;
                count[9]=count9;
                for(i=0;i<10;i++)
                {
                        if(count[i]!=0)
                        cout<<"\n "<<i<<"-"<<count[i];
                }


        }
        else
                cout<<"\n Invalid entry";
}

4. ///Print the largest occuring digit in an array of n numbers
#include<iostream>
using namespace std;
main()
{
        int
n,i,j,d,t,count0=0,count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0,count8=0,count9=0;
        cout<<"\n Enter the size of the array:";
        cin>>n;
        int a[n];
        int b[10];
        int e[10];
        if(n>0)
        {
                cout<<"\n Enter the elements into the array:";
                for(i=0;i<n;i++)
                        cin>>a[i];
                for(i=0;i<n;i++)
                {
                while(a[i]!=0)
                {
                        d=a[i]%10;
                        if(d==0)
                                count0++;
                        if(d==1)
                                count1++;
                        if(d==2)
                                count2++;
                        if(d==3)
                                count3++;
                        if(d==4)
                                count4++;
                        if(d==5)
                                count5++;
                        if(d==6)
                                count6++;
                        if(d==7)
                                count7++;
                        if(d==8)
                                count8++;
                        if(d==9)
                                count9++;
                        a[i]=a[i]/10;
                }
                }
                 b[0]=count0;
                 b[1]=count1;
                 b[2]=count2;
                 b[3]=count3;
                 b[4]=count4;
                 b[5]=count5;
                 b[6]=count6;
                 b[7]=count7;
                 b[8]=count8;
                 b[9]=count9;
                 for(i=0;i<10;i++)
                 {
                        e[i]=b[i];
                 }
                 for(i=0;i<10;i++)
                 {
                         for(j=i;j<10;j++)
                         {
                                 if(b[i]<b[j])
                                 {
                                         t=b[i];
                                         b[i]=b[j];
                                         b[j]=t;
                                 }
                         }
                 }
                 for(i=0;i<10;i++)
                 {
                         if(e[i]==b[0])
                 cout<<"\n The largest occuring digit is:"<<i;
                 }
        }
        else
                cout<<"\n Invalid entry";
}

5.//Arrange the array insuch a way that odd numbers come
first and then the even numbers
#include<iostream>
using namespace std;
main()
{
        int n,i,j,t,k;
        cout<<"\n Enter the size of the array:";
        cin>>n;
        int a[n];
        if(n>0)

        {
                cout<<"\n Enter the elements into the array:";
                for(i=0;i<n;i++)
                        cin>>a[i];
                cout<<"\n The original array is:";
                for(i=0;i<n;i++)
                        cout<<"\t"<<a[i];
                for(i=0;i<n;i++)
                {
                        if(a[i]%2==0)
                        {
                                for(j=i+1;j<n;j++)
                                {

                                        if(a[j]%2!=0)
                                        {
                                                t=a[j];
                                                a[j]=a[i];
                                                a[i]=t;
                                               i++;
                                                break;
                                        }
                                        for(k=i;k>0;k--)
                                        {
                                                a[k]=a[k-1];
                                        }


                                }

                        }

                }
                cout<<"\n the updated array is:";
                for(i=0;i<n;i++)
                        cout<<"\t"<<a[i];
        }
        else
                cout<<"\n Invalid entry";
}
 6.//Spread the digits of the array in the same array
#include<iostream>
using namespace std;
main()
{
        int n,i,j;
        cout<<"\n Enter the size of the array:";
        cin>>n;
        int a[n];
        if(n>0)
        {
                cout<<"\n Enter the numbers into the array:";
                for(i=0;i<n;i++)
                        cin>>a[i];
                cout<<"\n The original array is:";
                for(i=0;i<n;i++)
                        cout<<"\t"<<a[i];
                for(i=0;i<n;i++)
                {
                     if(a[i]<0)
                        a[i]=a[i]*-1;
                     if(a[i]<10)
                        continue;
                       while(a[i]>9)
                         {
                             n++;
                             r=a[i]%10;
                           for(j=n-1;j>i;j--)
                            {
                               a[j]=a[j-1];
                            }
                              a[i+1]=r;
                              a[i]=a[i]/10;
                          }
                 }
                cout<<"\n the updated array is:";
                for(i=0;i<n;i++)
                {
                    cout<<"\t"<<a[i];
                }
        }
        else
                cout<<"\n Invalid entry";
}

7.//Update the array so that an array element is followed by
its reverse
#include<iostream>
using namespace std;
main()
{
        int n,i,p,rev,d,j;
        cout<<"\n Enter the size of the array:";
        cin>>n;
        int a[2*n];
        if(n>0)
        {
                cout<<"\n Enter the numbers into the array:";
                for(i=0;i<n;i++)
                        cin>>a[i];
               cout<<"\n The original array is:";
                for(i=0;i<n;i++)
                cout<<"\t"<<a[i];
                for(i=0;i<n;i++)
                {

                        rev=0;
                        p=a[i];
                        while(p!=0)
                        {

                                d=p%10;
                                rev=(rev*10)+d;
                                p=p/10;
                        }
                               for(j=n;j>i;j--)
                                {
                                        a[j]=a[j-1];
                                }
                                n++;
                                i++;
                                a[i]=rev;
                }
                cout<<"\n The updated array is:";
              for(i=0;i<n;i++)
                {
                        cout<<"\t"<<a[i];
                }
        }
        else
                cout<<"\n Invalid entry";
}
8.//Store all palindrome numbers into another array
#include<iostream>
using namespace std;
main()
{
        int n,i,j,rev,r,num,m,count=0;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[n];
        int b[n];
        if(n>0)
        {
                cout<<"\n Enter the numbers:\n";
                for(i=0;i<n;i++)
                        cin>>a[i];
                cout<<"\n The original array is:";
                for(i=0;i<n;i++)

                cout<<"\t"<<a[i];
                cout<<"\n The updated array is:";
                for(i=0;i<n;i++)
                {
                        rev=0;
                        num=a[i];
                        while(a[i]!=0)
                        {
                                r=a[i]%10;
                                rev=(rev*10)+r;
                                a[i]=a[i]/10;
                        }
                        if(num==rev)
                        {
                        b[count]=num;
                        count++;
                        }
                }

        for(j=0;j<count;j++)
                        cout<<"\t"<<b[j];

        }
        else
                cout<<"\n Invalid entry";
}
9.//Merge two stored array in a sorted fashion
#include<iostream>
using namespace std;
main()
{
        int arr1[20],arr2[20],arr3[40],arr[40],temp;
        int i,j,k,t;
        int max1,max2;
        cout<<"Enter number of elements in the list 1:";
        cin>>max1;
        cout<<"\n Take the elements in sorted order:\n";
        for(i=0;i<max1;i++)
                        {
                        cout<<"Enter element"<<" "<<i+1<<":";
                        cin>>arr1[i];
                        }

        cout<<"\n Enter number of elements in the list 2:";
        cin>>max2;
        cout<<"\n Take the elements in sorted order:\n";
        for(j=0;j<max2;j++)
                {
                        cout<<"Enter element"<<" "<<j+1<<":";
                        cin>>arr2[j];
                        }

                i=0;
                j=0;
                k=0;
        while((i<max1) && (j<max2))
        {
                if(arr1[i]<arr2[j])
                        arr3[k++]=arr1[i++];
                else
                        arr3[k++]=arr2[j++];


        }
        while(i<max1)
                arr3[k++]=arr1[i++];
        while(j<max2)
                arr3[k++]=arr2[j++];

        cout<<"\n List 1:";
        for(i=0;i<max1;i++)
        cout<<"\t"<<arr1[i];
        cout<<"\n List 2:";
        for(j=0;j<max2;j++)
        cout<<"\t"<<arr2[j];
        cout<<"\n Merged list:";
        for(k=0;k<(i+j);k++)
        {
                for(t=0;t<(i+j);t++)
                {
                        if(arr3[k]<arr3[t])
                        {
                                temp=arr3[k];
                                arr3[k]=arr3[t];
                                arr3[t]=temp;
                        }
                }
        }
        for(t=0;t<(i+j);t++)
        {
                if(arr3[t]!=arr3[t+1])

cout<<"\t"<<arr3[t];

        }
        cout<<"\n";
}

                                                           
                                                           
                                                           
                                          
                                                           
                                                           
                


 
Is This Answer Correct ?    1 Yes 0 No
P.venkataramana
 
  Re: 1. Duplicate the even numbers. -1 Sample I/O Array1:- 4,2,24,3,22 Updated Array:- 4,4,2,2,24,24,3,22,22 2. Reverse the array in a region - 1 Sample I/O Array1:- 4,2,24,3,22,41,21 Enter Region:- 2,5 Update Array:-4,41,22,3,24,2,21 3. Store first the even digits in an array and then odd digits in same array -2 Sample I/O Array1:- 4,2,24,3,22,41,21 Array 2:- 4,2,2,4,2,2,4,2,3,1,1 4. Store the count of the digits in all numbers in an array and print the count. -2 Sample I/O Array1:- 4,2,9,3,7,41,28 Array 2:- 0,1,1,1,2,0,0,1,1,1 1-1;2-1;3-1;4-2;7-1;8-1;9-1 5. Store all palindrome numbers in to another array -2 Sample I/O Array1:- 4,22,9,313,7,141,28 Array 2:- 4,22,9,313,141 6. Arrange the array in such a way that odd numbers come first and then even numbers -1 Sample I/O Array1:- 4,22,9,313,7,141,28 Update Array1:- 9,313,7,141,4,22,28 7. Store into another array by inserting it in the right place - 2 Sample I/O Array1:- 4,22,9,313,7,141,28 Array2:- 4 /4,22 /4,9,22 /4,9,22 ,313 /4,7,9,22 ,313 /4,7,9,22 ,141,313 / 4,7,9,22,28 ,141,313 8. Merge two sorted arrays in a sorted fashion - 3 Sample I/O Array 1:- 3,6,7,9,11,16 Array 2:- 1,2,5,7,20 Array 3:- 1,2,3,5,6,7,9,11,16,20 9. Upadte the array so that an array element is followed by its revere - 1 Sample I/O Array 1:- 13,63,74,9,11,16 Updated Array 1:- 13,31,63,36,74,47,9,9,11,11,16,16 10.Spread the digits of the array in the same array. -1 Sample I/O Array 1:- 13,63,74,9,11,16 Updated Array 1:-1,3,6,3,74,9,1,1,1,6 11.Shift the boundary of array to have only 2 digit numbers. Sample I/O Array 1:- 139,643,74,9,101,126 Updated Array 1:- 13,96,43,74,91,11,26 12.Print the largest occuring digit in an array of N numbers. Sample I/O Array 1:- 13,63,74,9,11,16 1 occurs most.
Answer
# 2
1///Program to Duplicate the even numbers
#include<iostream>
using namespace std;
main()
{
        int n,i,j;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[2*n];
        if(n>0)
        {
        cout<<"Enter the numbers:";
        for(i=0;i<n;i++)
                cin>>a[i];
        cout<<"\n The original array is :";
        for(i=0;i<n;i++)
                cout<<"\t"<<a[i];
        for(i=0;i<=n;i++)
        {
               if(a[i]%2==0)
                {
                n++;
                for(j=n;j>i;j--)
                {
                        a[j]=a[j-1];
                }

                i++;
                a[i]=a[i-1];
                }
        }
        cout<<"\n The updated array is:";
        for(i=0;i<n-1;i++)
        {
                cout<<"\t"<<a[i];
        }
        }
        else
                cout<<"\n Invalid entry";
}
2.// Program to Reverse the array in the region
#include<iostream>
using namespace std;
main()
{
        int n,i,x,y,t;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[n];
        if(n>0)
        {
                cout<<"Enter the numbers:";
                for(i=1;i<=n;i++)
                        cin>>a[i];
                cout<<"Enter the positions for which the
array to be reversed from left to right:";
                cin>>x>>y;
                cout<<"\n the original array is:";
                for(i=0;i<n;i++)
                        cout<<a[i];
                if(x>y)
                {
                        t=x;
                        x=y;
                        y=t;
                }
                if(x<1 || y>n)
                        cout<<"\n Invalid entry";
                else
                {
                for(i=1;i<x;i++)
                {
                        cout<<"\t"<<a[i];
                }
                for(i=y;i>=x;i--)
                {
                        cout<<"\t"<<a[i];
                }
                for(i=y+1;i<=n;i++)
                {
                        cout<<"\t"<<a[i];
                }
                }
        }

        else
                cout<<"\n Invalid entry";
}

//Reverse the array in the region
#include<iostream>
using namespace std;
main()
{
        int n,i,x,y,t;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[n];
        if(n>0)
        {
                cout<<"Enter the numbers:";
                for(i=1;i<=n;i++)
                        cin>>a[i];
                cout<<"Enter the positions for which the
array to be reversed from left to right:";
                cin>>x>>y;
                cout<<"\n the original array is:";
                for(i=0;i<n;i++)
                        cout<<a[i];
                if(x>y)
                {
                        t=x;
                        x=y;
                        y=t;
                }
                if(x<1 || y>n)
                        cout<<"\n Invalid entry";
                else
                {
                for(i=1;i<x;i++)
                {
                        cout<<"\t"<<a[i];
                }
                for(i=y;i>=x;i--)
                {
                        cout<<"\t"<<a[i];
                }
                for(i=y+1;i<=n;i++)
                {
                        cout<<"\t"<<a[i];
                }
                }
        }

        else
                cout<<"\n Invalid entry";
}
3.//Store the count of the digits in all numbers in an array
and print the count
#include<iostream>
using namespace std;
main()
{
        int
n,i,d,count0=0,count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0,count8=0,count9=0;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[n];
        int count[10];
        if(n>0)
        {
                cout<<"\n Enter the numbers:\n";
                for(i=0;i<n;i++)
                        cin>>a[i];
                cout<<"\n The original array is:";
                        for(i=0;i<n;i++)
                                cout<<"\t"<<a[i];
                for(i=0;i<n;i++)
                {

                while(a[i]!=0)
                {

                        d=a[i]%10;
                        if(d==0)
                                count0++;
                        if(d==1)
                                count1++;
                        if(d==2)
                                count2++;
                        if(d==3)
                                count3++;
                        if(d==4)
                                count4++;
                        if(d==5)
                                count5++;
                        if(d==6)
                                count6++;
                        if(d==7)
                                count7++;
                        if(d==8)
                                count8++;
                        if(d==9)
                                count9++;
                        a[i]=a[i]/10;
                }
                }
                count[0]=count0;
                count[1]=count1;
                count[2]=count2;
                count[3]=count3;
                count[4]=count4;
                count[5]=count5;
                count[6]=count6;
                count[7]=count7;
                count[8]=count8;
                count[9]=count9;
                for(i=0;i<10;i++)
                {
                        if(count[i]!=0)
                        cout<<"\n "<<i<<"-"<<count[i];
                }


        }
        else
                cout<<"\n Invalid entry";
}

4. ///Print the largest occuring digit in an array of n numbers
#include<iostream>
using namespace std;
main()
{
        int
n,i,j,d,t,count0=0,count1=0,count2=0,count3=0,count4=0,count5=0,count6=0,count7=0,count8=0,count9=0;
        cout<<"\n Enter the size of the array:";
        cin>>n;
        int a[n];
        int b[10];
        int e[10];
        if(n>0)
        {
                cout<<"\n Enter the elements into the array:";
                for(i=0;i<n;i++)
                        cin>>a[i];
                for(i=0;i<n;i++)
                {
                while(a[i]!=0)
                {
                        d=a[i]%10;
                        if(d==0)
                                count0++;
                        if(d==1)
                                count1++;
                        if(d==2)
                                count2++;
                        if(d==3)
                                count3++;
                        if(d==4)
                                count4++;
                        if(d==5)
                                count5++;
                        if(d==6)
                                count6++;
                        if(d==7)
                                count7++;
                        if(d==8)
                                count8++;
                        if(d==9)
                                count9++;
                        a[i]=a[i]/10;
                }
                }
                 b[0]=count0;
                 b[1]=count1;
                 b[2]=count2;
                 b[3]=count3;
                 b[4]=count4;
                 b[5]=count5;
                 b[6]=count6;
                 b[7]=count7;
                 b[8]=count8;
                 b[9]=count9;
                 for(i=0;i<10;i++)
                 {
                        e[i]=b[i];
                 }
                 for(i=0;i<10;i++)
                 {
                         for(j=i;j<10;j++)
                         {
                                 if(b[i]<b[j])
                                 {
                                         t=b[i];
                                         b[i]=b[j];
                                         b[j]=t;
                                 }
                         }
                 }
                 for(i=0;i<10;i++)
                 {
                         if(e[i]==b[0])
                 cout<<"\n The largest occuring digit is:"<<i;
                 }
        }
        else
                cout<<"\n Invalid entry";
}

5.//Arrange the array insuch a way that odd numbers come
first and then the even numbers
#include<iostream>
using namespace std;
main()
{
        int n,i,j,t,k;
        cout<<"\n Enter the size of the array:";
        cin>>n;
        int a[n];
        if(n>0)

        {
                cout<<"\n Enter the elements into the array:";
                for(i=0;i<n;i++)
                        cin>>a[i];
                cout<<"\n The original array is:";
                for(i=0;i<n;i++)
                        cout<<"\t"<<a[i];
                for(i=0;i<n;i++)
                {
                        if(a[i]%2==0)
                        {
                                for(j=i+1;j<n;j++)
                                {

                                        if(a[j]%2!=0)
                                        {
                                                t=a[j];
                                                a[j]=a[i];
                                                a[i]=t;
                                               i++;
                                                break;
                                        }
                                        for(k=i;k>0;k--)
                                        {
                                                a[k]=a[k-1];
                                        }


                                }

                        }

                }
                cout<<"\n the updated array is:";
                for(i=0;i<n;i++)
                        cout<<"\t"<<a[i];
        }
        else
                cout<<"\n Invalid entry";
}
 6.//Spread the digits of the array in the same array
#include<iostream>
using namespace std;
main()
{
        int n,i,j;
        cout<<"\n Enter the size of the array:";
        cin>>n;
        int a[n];
        if(n>0)
        {
                cout<<"\n Enter the numbers into the array:";
                for(i=0;i<n;i++)
                        cin>>a[i];
                cout<<"\n The original array is:";
                for(i=0;i<n;i++)
                        cout<<"\t"<<a[i];
                for(i=0;i<n;i++)
                {
                     if(a[i]<0)
                        a[i]=a[i]*-1;
                     if(a[i]<10)
                        continue;
                       while(a[i]>9)
                         {
                             n++;
                             r=a[i]%10;
                           for(j=n-1;j>i;j--)
                            {
                               a[j]=a[j-1];
                            }
                              a[i+1]=r;
                              a[i]=a[i]/10;
                          }
                 }
                cout<<"\n the updated array is:";
                for(i=0;i<n;i++)
                {
                    cout<<"\t"<<a[i];
                }
        }
        else
                cout<<"\n Invalid entry";
}

7.//Update the array so that an array element is followed by
its reverse
#include<iostream>
using namespace std;
main()
{
        int n,i,p,rev,d,j;
        cout<<"\n Enter the size of the array:";
        cin>>n;
        int a[2*n];
        if(n>0)
        {
                cout<<"\n Enter the numbers into the array:";
                for(i=0;i<n;i++)
                        cin>>a[i];
               cout<<"\n The original array is:";
                for(i=0;i<n;i++)
                cout<<"\t"<<a[i];
                for(i=0;i<n;i++)
                {

                        rev=0;
                        p=a[i];
                        while(p!=0)
                        {

                                d=p%10;
                                rev=(rev*10)+d;
                                p=p/10;
                        }
                               for(j=n;j>i;j--)
                                {
                                        a[j]=a[j-1];
                                }
                                n++;
                                i++;
                                a[i]=rev;
                }
                cout<<"\n The updated array is:";
              for(i=0;i<n;i++)
                {
                        cout<<"\t"<<a[i];
                }
        }
        else
                cout<<"\n Invalid entry";
}
8.//Store all palindrome numbers into another array
#include<iostream>
using namespace std;
main()
{
        int n,i,j,rev,r,num,m,count=0;
        cout<<"How many numbers do u want to enter:";
        cin>>n;
        int a[n];
        int b[n];
        if(n>0)
        {
                cout<<"\n Enter the numbers:\n";
                for(i=0;i<n;i++)
                        cin>>a[i];
                cout<<"\n The original array is:";
                for(i=0;i<n;i++)

                cout<<"\t"<<a[i];
                cout<<"\n The updated array is:";
                for(i=0;i<n;i++)
                {
                        rev=0;
                        num=a[i];
                        while(a[i]!=0)
                        {
                                r=a[i]%10;
                                rev=(rev*10)+r;
                                a[i]=a[i]/10;
                        }
                        if(num==rev)
                        {
                        b[count]=num;
                        count++;
                        }
                }

        for(j=0;j<count;j++)
                        cout<<"\t"<<b[j];

        }
        else
                cout<<"\n Invalid entry";
}
9.//Merge two stored array in a sorted fashion
#include<iostream>
using namespace std;
main()
{
        int arr1[20],arr2[20],arr3[40],arr[40],temp;
        int i,j,k,t;
        int max1,max2;
        cout<<"Enter number of elements in the list 1:";
        cin>>max1;
        cout<<"\n Take the elements in sorted order:\n";
        for(i=0;i<max1;i++)
                        {
                        cout<<"Enter element"<<" "<<i+1<<":";
                        cin>>arr1[i];
                        }

        cout<<"\n Enter number of elements in the list 2:";
        cin>>max2;
        cout<<"\n Take the elements in sorted order:\n";
        for(j=0;j<max2;j++)
                {
                        cout<<"Enter element"<<" "<<j+1<<":";
                        cin>>arr2[j];
                        }

                i=0;
                j=0;
                k=0;
        while((i<max1) && (j<max2))
        {
                if(arr1[i]<arr2[j])
                        arr3[k++]=arr1[i++];
                else
                        arr3[k++]=arr2[j++];


        }
        while(i<max1)
                arr3[k++]=arr1[i++];
        while(j<max2)
                arr3[k++]=arr2[j++];

        cout<<"\n List 1:";
        for(i=0;i<max1;i++)
        cout<<"\t"<<arr1[i];
        cout<<"\n List 2:";
        for(j=0;j<max2;j++)
        cout<<"\t"<<arr2[j];
        cout<<"\n Merged list:";
        for(k=0;k<(i+j);k++)
        {
                for(t=0;t<(i+j);t++)
                {
                        if(arr3[k]<arr3[t])
                        {
                                temp=arr3[k];
                                arr3[k]=arr3[t];
                                arr3[t]=temp;
                        }
                }
        }
        for(t=0;t<(i+j);t++)
        {
                if(arr3[t]!=arr3[t+1])

cout<<"\t"<<arr3[t];

        }
        cout<<"\n";
}

                                                           
                                                           
                                                           
                                          
                                                           
                                                           
                


 
Is This Answer Correct ?    1 Yes 0 No
P.venkataramana
 
 
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); } wat is the o/p and how?  7
what is compiler  5
What is RAM memory? and What is ROM?Who designed one is temparary and another is permanent?why they designed like that?By using far pointer which type data(whether hexadecimal)we can access? Excel1
what is op? for(c=0;c=1000;c++) printf("%c",c); Trigent18
Hi, main() { } Is a user defined function or Built in Functionn Honeywell9
What character terminates all strings composed of character arrays? 1) 0 2) . 3) END  3
implement general tree using link list Wipro1
what is a static function Satyam10
main() { printf("hello%d",print("QUARK test?")); }  4
Write code for finding depth of tree Adobe1
write a program to print the all 4digits numbers & whose squares must me even numbers? Virtusa2
differentiate between const char *a; char *const a; and char const *a; HCL1
dennis ritchie invented C language in AT&T bell laboratory what is the extension of AT&T?  1
An interactive c program to read basic salary of 15 persons. each person gets 25% of basic as HRA, 15%of basic as conveyance allowances, 10%of basic as entertainment allowances.The total salary is calculated by adding basic+HRA+CA+EA.Calculate how many out of 15 get salary above 10,000.Rs also print the salary of each employee  2
What is a symbolic constant?  1
What are the different pointer models in c?  3
what is difference between ++(*p) and (*p)++ Accenture15
What will be result of the following program? void myalloc(char *x, int n) { x= (char *)malloc(n*sizeof(char)); memset(x,\0,n*sizeof(char)); } main() { char *g="String"; myalloc(g,20); strcpy(g,"Oldstring"); printf("The string is %s",g); } a) The string is : String b) Run time error/Core dump c) The string is : Oldstring d) Syntax error during compilation e) None of these IBM3
What is the diffrent between while and do while statement ?  5
what is the difference between #include<stdio.h> and #include"stdio.h" ? TCS5
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com