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 is a dynamic array in c?
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.
Are negative numbers true in c?
Write the test cases for checking a variable having value in range -10.0 to +10.0?
Subtract Two Number Without Using Subtraction Operator
How is null defined in c?
while initialization of array why we use a[][2] why not a[2][]...?
Why is #define used?
Write the control statements in C language
Is using exit() the same as using return?
typedef enum { html, java, javascript, perl, cgi } lang;The above statement defines a : a) Union b) User defined type c) Enumerated variable d) none
What are the difference between a free-standing and a hosted environment?
hi send me sample aptitude papers of cts?
i got 75% in all semester am i eligible for your company
What is the sizeof () operator?