C program to swap array without using other array
//Written in Dev C this program will swap all the values of an array #include <stdio.h>
#include<Conio.h>
int main()
{
int array[100], n, c, t, end;
printf("\n enter the no. of elements :");
scanf("%d", &n);
end = n - 1;
for (c = 0; c < n; c++) {
scanf("%d", &array[c]);
}
for (c = 0; c < n/2; c++) {
t = array[c];
array[c] = array[end];
array[end] = t;
end--;
}
printf("Reversed array elements are:\n");
for (c = 0; c < n; c++) {
printf("%d\n", array[c]);
}
getch();
}
// for those who want to use clrscr(); in dev c . You can use system("cls") in place of clrscr(); before using system("cls") dont forget to add #include<stdlib.h> in the top system("cls") is declared in stdlib.h
No comments:
Post a Comment