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

How is a pointer variable declared?

0 Answers  


What type is sizeof?

0 Answers  


a=(1,2,3); b=1,2,3; c=1,(2,3); d=(1,2),3; what's the value of 'a','b','c','d'

2 Answers  


What is boolean in c?

0 Answers  


What is the easiest sorting method to use?

0 Answers  






52.write a “Hello World” program in “c” without using a semicolon? 53.Give a method to count the number of ones in a 32 bit number? 54.write a program that print itself even if the source file is deleted? 55.Given an unsigned integer, find if the number is power of 2?

9 Answers  


How are pointers declared in c?

0 Answers  


What's the best way of making my program efficient?

0 Answers   Celstream,


What is a constant and types of constants in c?

0 Answers  


what is a pointer

4 Answers   Bank Of America, TCS,


25. It takes five minutes to pass a rumour from one person to two other persons. The tree of rumour continues. Find how many minutes does it take spread the rumour to 768 persons. ?

11 Answers   CTS, TCS,


Explain the advantages of using macro in c language?

0 Answers  


Categories