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
What is static and volatile in c?
What do you mean by dynamic memory allocation in c?
What are the types of pointers?
What is preprocessor with example?
What is the use of clrscr?
What is use of #include in c?
What is the difference between exit() and _exit() function in c?
Explain what are global variables and explain how do you declare them?
How do c compilers work?
void main(int n) { if(n==0) return; main(--n); printf("%d ",n); getch(); } how it work and what will be its output...............it any one know ans plz reply
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
How can this be legal c?
What is calloc malloc realloc in c?
What is bin sh c?
What are the loops in c?