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
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
What is use of integral promotions in c?
When should structures be passed by values or by references?
What is c programing language?
What are valid operations on pointers?
What are the types of arrays in c?
What is wrong with this declaration?
What are Macros? What are its advantages and disadvantages?
What is meant by initialization and how we initialize a variable?
What is 'bus error'?
What are c preprocessors?
What are the valid places to have keyword “break”?
Why is it important to memset a variable, immediately after allocating memory to it ?
Is main an identifier in c?
What is the role of this pointer?