Program to swap the any two elements in an array containing N number of elements?
#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 |
What is enumerated data type in c?
what is the output of printf("%d",(scanf("%d",10));
How to access or modify the const variable in c ?
16 Answers HCL, HP,
What is a C array and illustrate the how is it different from a list.
How can you pass an array to a function by value?
What is c standard library?
do u print this format '(((())))'. This brackets is based on user input like 4 or 5 or 6,without using any loop's?
What is logical error?
What are the header files used in c language?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it
5 Answers ABS, Accenture, HCL, Infosys, Infotech, SoftSolve, Software India, TCS, Vertex, Vimukti Technologies,
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none