Program to print array elements in reverse order | My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Saturday, February 8, 2020

Program to print array elements in reverse order | My CS Tutorial

C program to print array elements in reverse order by swapping method.

In this tutorial we will solve a problem that find or print a new array list in which all elements are available in reversed form. All elements are reversed by swapping method.

Here we will write a c program source code to print reverse list of array elements.

This program will accept the range or size of an array that entered by user through the keyboard.
After it we will enter the elements of this array.

After these steps compiler check and execute the conditions and print the reverse form of array elements.


C PROGRAM CODE


#include<stdio.h>
#include<conio.h>
void main()
{
 int i,a[100],c,k,j,n,num;
clrscr();

 printf("\n ENTER SIZE OF THIS ARRAY:\n ");
 scanf("%d",&num);

 printf("\n ENTER NUMBERS OF THIS ARRAY:\n ");

 for(i=0;i<num;i++)
 {
  scanf("%d",&a[i]);
 }

 printf("\n BEFORE ARRANGE, THE ARRAY IS:\n ");
 for(i=0;i<num;i++)

 printf("%d\n ",a[i]);

 k=num;
 while(k>=0)
 {
  for(j=0;j<k-1;j++)
  {
   //using swap method
   c=a[j];
   a[j]=a[j+1];
   a[j+1]=c;
  }
  k--;
 }

 printf("\n AFTER ARRANGE, THE ARRAY IS:\n ");
 for(i=0;i<num;i++)
 printf("%d\n ",a[i]);

getch();
}


OUTPUT:






Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment