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


Please Help Members By Posting Answers For Below Questions

What does volatile do?

561


write a program to print largest number of each row of a 2D array

1866


How can you increase the size of a dynamically allocated array?

639


What are the advantages of union?

624


Explain modulus operator. What are the restrictions of a modulus operator?

595






Add Two Numbers Without Using the Addition Operator

351


What is spark map function?

578


Write a program for Overriding.

679


in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none

595


What will be the outcome of the following conditional statement if the value of variable s is 10?

755


What is array in c with example?

610


hai iam working in sap sd module for one year and working in lumax ind ltd in desp department but my problem is i have done m.b.a in hr/marketing and working sap sd there is any combination it. can you give right solution of my problem. and what can i do?

1654


How many parameters should a function have?

661


to find the closest pair

1816


What is #define size in c?

640