Program to swap the any two elements in an array containing N number of elements?
#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 |
What is the c language function prototype?
How to reverse a linked list
1 Answers Aricent, Fidelity, IBM, TCS,
Why do we use static in c?
What are the features of c languages?
what is diference between return 0 and return NULL??
What is period operator in c?
what is the use of macro program
Can a variable be both static and volatile in c?
how can you print&scan anything using just one character? :) HINT: printf,scanf similer
Explain what is wrong with this program statement? Void = 10;
which is the best antivirus and how to update it
write a program to search for an element in a given array. If the array was found then display its position otherwise display appropriate message in c language