Problem statement
Write a c program to reverse an array of integers without using recursion
Write a c program to reverse an array of integers without using recursion
#include<stdio.h>
void reverse(int a[],int i);
int main()
{
int a[55],i,n,z;
printf("enter the array and enter ctrl-d in the end \n");
i=0;
while(scanf("%d",&z)!=EOF)
{
a[i]=z;
i++;
}
reverse(a,i);
for(n=0;n<i;n++)
{
printf("%d ",a[n]);
}
return 0;
}
void reverse(int a[],int i)
{
int temp,j;
for(j=0;j<i/2;j++)
{
temp=a[i-j-1];
a[i-j-1]=a[j];
a[j]=temp;
}
return ;
}
No comments:
Post a Comment