Wednesday 6 February 2013

Write a c program to accept n numbers from user store these numbers into an array & reverse an array elements using function


#include<stdio.h>
#include<conio.h>
  void rev(int);
  void main()
{
  int n;
  clrscr();
  printf("\nEnter the n number: ");
  scanf("%d",&n);
  rev(n);
  getch();
}
  void rev(int n)
{
  int a[10],i;
  printf("\nEnter the array elements: ");
  for(i=0;i<n;i++)
{
  scanf("%d",&a[i]);
}
  printf("\nThe reverse array is: ");
  for(i=n;i>=0;i--)
{
  printf("%d\t",a[i]);
}
}

//OUTPUT:

//Enter the n number: 4

//Enter the array elements: 1
//2
//3
//4

//The reverse array is: 4       3       2       1

No comments:

Post a Comment