Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 Posted / p.venkataramana

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 ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How can a number be converted to a string?

1241


Why array is used in c?

971


What is the data segment that is followed by c?

1032


What's a good way to check for "close enough" floating-point equality?

1095


What is pointer in c?

1141


How to create struct variables?

1045


in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above

1016


What does != Mean in c?

987


What is time null in c?

1005


A character flag or control mechanism that delineates one data item from another a) variable b) constant c) delimiter d) call by reference

1044


How can I do graphics in c?

982


What is the difference between union and anonymous union?

1249


What are qualifiers in c?

983


What is the best way to comment out a section of code that contains comments?

1263


What is the explanation for modular programming?

1148