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 is a dynamic array in c?

846


One of the Institutes contains 5 student groups. Every group contains 4 students. Institute wants to store student group’s details in array. Group should contain group member’s details (name and registration number and age), project name, and mark of the group.

2442


Are negative numbers true in c?

797


Write the test cases for checking a variable having value in range -10.0 to +10.0?

2104


Subtract Two Number Without Using Subtraction Operator

617


How is null defined in c?

890


while initialization of array why we use a[][2] why not a[2][]...?

2122


Why is #define used?

1039


Write the control statements in C language

896


Is using exit() the same as using return?

947


typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none

991


What are the difference between a free-standing and a hosted environment?

1041


hi send me sample aptitude papers of cts?

1918


i got 75% in all semester am i eligible for your company

1973


What is the sizeof () operator?

815