C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
12 comments:
What to do if both arrays are of unequal length?
Same program by using pointers.
#include
void swap(int *, int *);
main()
{
int a[10],b[10],i;
printf("Enter First array->");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\nEnter Second array->");
for(i=0;i<10;i++)
scanf("%d",&b[i]);
for(i=0;i<10;i++)
swap(&a[i], &b[i]);
printf("\nArrays after swapping");
printf("\nFirst array->");
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\nSecond array->");
for(i=0;i<10;i++)
printf("%d ",b[i]);
}
void swap(int *arr1, int *arr2)
{
int temp;
temp = *arr1;
*arr1 = *arr2;
*arr2 = temp;
}
can u write a program by using array......such as
scanf 8 number then printf b[1]=1 b[2]=2 b[3]=3...b[8]=8 then convert it b[1]=8 b[2]=7....b[8]=1 ....please write this program...my fb id /mi.tanim.1
why dont you dynamically allocate array and change the address
just ur r swapping the elements of two arrays so, I think no need of equal length to swap each other
before dat in program they're reading 10 values for each array
can't we write the program with out using swap keyword using pointers
#include
#include
#include
int b[10],a[10],n,g,i,u;
void dd(int);
void main()
{
clrscr();
printf("enter ");
scanf("%d",&n);
if(n==0)
{
printf("please enter valid array");
goto g;
}
for(i=0;ig)
{
for(i=g;i<n;i++)
b[i]=a[i];
}
for(i=0;i<g;i++)
printf("\n%d",a[i]);
for(i=0;i<n;i++)
printf("\n%d",b[i]);
g:
getch();
}
void dd(int u)
{
if(a[i]!=0)
{
b[i]=a[i];
a[i]=u;
}
else
a[i]=b[i];
}
if arrays are of un equal size then you just no need to mention its size
like:
int a[10]
int b[10]
answer to you is :
int a[size]
int b[size]
How can numbers between two arrays be swapped with their positions?
Accept two different arrays and interchange it
Please help me to find the answer
Post a Comment