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 |
write a program to find the given number is prime or not
2 Answers Accenture, Vasutech,
What is Bitwise Operator and how it works?
int i=0,j; j=++i + ++i ++i; printf(" %d",j);
What is structure padding & expalain wid example what is bit wise structure?
write a c program to change only the 3rd bit of the particular number such that other bits are not affected.. if bitnum=10(say.. it can be any no..
Why does the call char scanf work?
How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
Define the scope of static variables.
Explain what are linked list?
How are Structure passing and returning implemented by the complier?
What is the difference b/w main() in C language and main() in C++.
I have a function which accepts, and is supposed to initialize,a pointer, but the pointer in the caller remains unchanged.