Q. Write a c program to accept n elements from user and reverse all elements.
Ans.
/*c program for reverse an array*/
#include<stdio.h>
#include<conio.h>
#define S 50
int main()
{
int i,num,mid;
float arr[S],tmp;
printf("Ener total number of element in array : ");
scanf("%d", &num);
for(i=0; i<num; i++)
{
printf("Enter %d element : ",i+1);
scanf("%f", &arr[i]);
}
mid = num/2;
for(i=0; i<mid; i++)
{
/*swapping*/
tmp = arr[i];
arr[i]= arr[num-1-i];
arr[num-1-i] = tmp;
}
printf("\n-- Array in reverse order --\n\n");
for(i=0; i<num; i++)
printf("\t%.2f\n",arr[i]);
getch();
return 0;
}
/************Output************/
Related program:
Ans.
/*c program for reverse an array*/
#include<stdio.h>
#include<conio.h>
#define S 50
int main()
{
int i,num,mid;
float arr[S],tmp;
printf("Ener total number of element in array : ");
scanf("%d", &num);
for(i=0; i<num; i++)
{
printf("Enter %d element : ",i+1);
scanf("%f", &arr[i]);
}
mid = num/2;
for(i=0; i<mid; i++)
{
/*swapping*/
tmp = arr[i];
arr[i]= arr[num-1-i];
arr[num-1-i] = tmp;
}
printf("\n-- Array in reverse order --\n\n");
for(i=0; i<num; i++)
printf("\t%.2f\n",arr[i]);
getch();
return 0;
}
/************Output************/
Screen shot for reverse array C program |
Related program:
Comments
Post a Comment