Sponsor Area
Write a function SWAP2BEST (int ARR[], int Size) in C++ to modify the content of the array in such a way that the elements, which are multiples of 10 swap with the value present in the very next position in the array.
For example:
If the content of array ARR is 90,56,45,20,34,54
The content of array ARR should become 56,90,45,34,20,54
#include <iostream.h>
#include <conio.h>
void SWAP2BEST(int ARR[], int Size);
int main ()
{
//Here we are taking different values for more perfect result with more
//numbers of array elements. You can change the values and number of array
//elements as per your choice.
int ListofNum[8] = {6, 28, 30, 17, 50, 45, 80, 82};
clrscr();
SWAP2BEST(ListofNum, 8 ) ;
return 0;
}
void SWAP2BEST(int ARR[], int Size)
{
int i= 0; int temp=0;
#include <iostream.h>
#include <conio.h>
void SWAP2BEST(int ARR[], int Size);
int main ()
{
//Here we are taking different values for more perfect result with more
//numbers of array elements. You can change the values and number of array
//elements as per your choice.
int ListofNum[8] = {6, 28, 30, 17, 50, 45, 80, 82};
clrscr(); SWAP2BEST(ListofNum, 8 ) ;
return 0;
}
void SWAP2BEST(int ARR[], int Size)
{
int i= 0; int temp=0;
for (i = 0; i < Size; ++i)//loop for printing original array values
{
cout<<ARR[i]<<;
}
cout<<endl;
for (i = 0; i < Size; ++i)
{
if(ARR[i+1]=='\0')
{
}
else
{
if(ARR[i+1]%10==0)
{
temp=ARR[i];
ARR[i]=ARR[i+1];
ARR[i+1]=temp;
}
}
}
for (i = 0; i < Size; ++i) //loop for printing swapped array value
{
cout<<ARR[i]<<;
}
}
An array T[20][10] is stored in the memory along the column with each of the element occupying 2 bytes, find out the memory location of T[10][5], if an element T[2][9] is stored at location 7600.
AssumingLBR=LBC=0
B=7600
W=2 bytes
Number of Rows(N)=20
Number of Columns(M)=10
LOC(Arr[I] [J]) = B +(I + J*N)*W
LOC(T[10][5]) = 7600+(10+5*20)*2
= 7600 + (300*2)
= 7600 + 600
= 8200
Sponsor Area
Sponsor Area