Program to swap the any two elements in an array containing N number of elements?
Answer Posted / baluusa8
#include<stdio.h>
void swaparray(int *,int *);
void main()
{
int n,num[10],i,element,k,l;
printf("Enter number of elements
");
scanf("%d",&n);
printf("Enter the elements
");
for(i=0;i<n;i++)
{
scanf("%d",&element);
num[i]=element;
}
printf("Original array
");
for(i=0;i<n;i++)
printf("num[%d]=%d
",i,num[i]);
printf("ENter places to be swapped");
scanf("%d%d",&k,&l);
swaparray(num+k,num+l);
printf("AFTER SWAPPING
");
for(i=0;i<n;i++)
printf("num[%d]=%d
",i,num[i]);
}
void swaparray(int *a, int *b)
{
int temp;
temp = *a;
*a = *b;
*b = temp;
}
| Is This Answer Correct ? | 7 Yes | 1 No |
Post New Answer View All Answers
How a string is stored in c?
How can you return multiple values from a function?
What functions are in conio h?
What is a pointer value and address in c?
What is the function of this pointer?
Why doesnt that code work?
What is the use of linkage in c language?
How to draw the flowchart for structure programs?
What do you know about the use of bit field?
What are compound statements?
why use "return" statement a) on executing the return statement it immediately transfers the control back to the calling program b) it returns the value present in the parentheses return, to the calling program c) a & b d) none of the above
Create a simple code fragment that will swap the values of two variables num1 and num2.
What are the advantage of c language?
write a program to display all prime numbers
Explain what is the difference between the expression '++a' and 'a++'?