Find Reverse of Array

-- Leave a Comment
The Question is Read 10 numbers in array and print Reverse Order. To Print in Reverse Order we can run the loop from highest point with decrements But thee we Reverse the Array. Lets begun.
Codes Goes Here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<conio.h>
main()
 {
  int a[10],i,n,tmp;
  printf("How many Values you want to insert in the array\?");
  scanf("%d",&n);
  printf("Enter the values in the array");
  for(i=0;i<n;i++)
   scanf("%d".&a[i]);
  for(i=0;i<n/2;i++)
   {
    tmp=a[i];
    a[i]=a[n-i];
    a[n-i]=tmp;
   }
  printf("Now The Reverse is:- \n);
  for(i=;i<n;i++)
   printf("%d \t",i);
  getche();
 }

for(i=0;i<n/2;i++)
Here this Loop Swap the values. So we need to run the program for just half time of total values in Array. If the loops runs for n times it will swap values back. As we define n as int. so n/2 will always be int. If you need more explanation don't forget to ask through comment.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University. I know something about Linux, Android, Java, Nodejs, Unity3D and 3 dots :)

0 comments:

Post a Comment