Program to swap the any two elements in an array containing N number of elements?



Program to swap the any two elements in an array containing N number of elements?..

Answer / 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

More C Interview Questions

What are the key features in c programming language?

0 Answers  


what are the files which are automatically opened when a c file is executed?

3 Answers  


write a program to generate 1st n fibonacci prime number

12 Answers  


Write a c program to Find the name that you entered is male name or female name? Such as Sunjay is name of male and Payal is name of female

5 Answers   Infosys, Luminous,


Write a program to generate random numbers in c?

0 Answers  






int n=1; while(1) { switch(n) { case 1:printf("a"); n++; continue; case 2:printf("b"); n++; continue; default : printf("c"); break; } break; }

1 Answers  


what are bit fields? What is the use of bit fields in a structure declaration?

0 Answers   Flextronics, TISL, Virtusa,


Without using main fn and semicolon,print remainder for a given number in C language

2 Answers  


what is associativity explain what is the precidence for * and & , * and ++ how the folloing declaration work 1) *&p; 2) *p++;

0 Answers   L&T,


WHAT IS HEADER?

8 Answers   ProKarma, TCS,


How can I find the day of the week given the date?

0 Answers  


Write a program to compute the following 1!+2!+...n!

4 Answers  


Categories