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
What does volatile do?
write a program to print largest number of each row of a 2D array
How can you increase the size of a dynamically allocated array?
What are the advantages of union?
Explain modulus operator. What are the restrictions of a modulus operator?
Add Two Numbers Without Using the Addition Operator
What is spark map function?
Write a program for Overriding.
in programming languages a statement or part of a statement that specifies several different execution sequences a) constructs b) distructs c) executes d) none
What will be the outcome of the following conditional statement if the value of variable s is 10?
What is array in c with example?
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?
How many parameters should a function have?
to find the closest pair
What is #define size in c?