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

write a c program to remove all the duplicate characters in a string and replace with single character? ex:-input- AAABBBCCC output- ABC

2 Answers   HCL,


Explain Function Pointer?

0 Answers   Wipro,


A text file that contains declarations used by a group of functions,programs,or users a) executable file b) header file c) obj file d) .cfile

0 Answers  


How to run c Program without using IDE of c. means if program made in notepad.then how to compile by command prompt.

1 Answers   HP, TCS,


mplementation of stack using any programing language

1 Answers   Marlabs,






is it possible to create your own header files?

0 Answers  


What is a memory leak? How to avoid it?

1 Answers  


what is the output on the screen? int n; n=printf("my name is %d",printf("kiran %d",printf("kumar"))); printf("\n %d \n",n);

4 Answers   TCS,


Is double link list a linear data structure? If Yes, Why?If No, Why?

4 Answers  


the process of defining something in terms of itself is called (or) in C it is possible for the functions to call themselves. A function called a) nested function b) void function c) recursive function d) indifinite function

0 Answers  


#include<stdio.h> void main() { int a,b,c; a=b=c=1; c=++a || ++b && ++c; printf("%d\t%d\t%d",a,b,c); }

3 Answers  


What is getche() function?

0 Answers  


Categories