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 s in c?
How do we declare variables in c?
How can I make it pause before closing the program output window?
What is the difference between constant pointer and constant variable?
What is masking?
Does * p ++ increment p or what it points to?
There seem to be a few missing operators ..
List out few of the applications that make use of Multilinked Structures?
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
What are the 4 data types?
What are the 5 types of organizational structures?
Is it valid to address one element beyond the end of an array?
What would be an example of a structure analogous to structure c?
Can a function be forced to be inline? Also, give a comparison between inline function and the C macro?
What is the method to save data in stack data structure type?