Sunteți pe pagina 1din 8

9/26/2016 CProgramtoReadintegersintoanarrayandReversingthemusingPointers1DArrayPrograms,PointerProgramsc4learn.

com

Table of Content

C Program to Access Address of Variable using Pointer (http://www.c4learn.com/c-programs/program-

to-access-address-of-variable.html)

C Program to Accessing Value from Address using Pointer (http://www.c4learn.com/c-programs/pointer-

accessing-value-from-address-in.html)

C Program to Calculate Area of Circle using Pointer (http://www.c4learn.com/c-programs/calculating-

area-of-circle-using.html)

One Dimensional Array All Programs (http://www.c4learn.com/c-programs/one-dimensional-array-all-

programs.html)

C Program to Read Array Elements (http://www.c4learn.com/c-programs/c-program-rading-array-

elements.html)

C Program to Print Array Elements (http://www.c4learn.com/c-programs/printing-array-elements-in-c-

language.html)

C Program to Delete an element from the specied location from Array (http://www.c4learn.com/c-

programs/program-for-deletion-of-element-from.html)

C Program to Insert an element in an Array (http://www.c4learn.com/c-programs/program-insert-

element-in-array.html)

C Program to Copy all elements of an array into Another array (http://www.c4learn.com/c-

programs/copy-all-elements-of-array-into-another.html)

C Program to Search an element in Array (http://www.c4learn.com/c-programs/searching-element-in-

array.html)

C Program to Merge Two arrays in C Programming (http://www.c4learn.com/c-programs/merging-of-

two-arrays-in-c-programming.html)

C Program to Reversing an Array Elements in C Programming (http://www.c4learn.com/c-

programs/reversing-of-array-elements-in-c.html)

C Program to Find Largest Element in Array in C Programming (http://www.c4learn.com/c-

http://www.c4learn.com/cprograms/cprogramusingpointersreadarrayofintegersandreverseit.html 1/8
9/26/2016 CProgramtoReadintegersintoanarrayandReversingthemusingPointers1DArrayPrograms,PointerProgramsc4learn.com

programs/nd-largest-element-in-array-in-c.html)

C Program to Find Smallest Element in Array in C Programming (http://www.c4learn.com/c-

programs/nd-smallest-element-in-array-in-c.html)

C Program to Calculate Addition of All Elements in Array (http://www.c4learn.com/c-programs/addition-

of-all-elements-in-array.html)

C Program to Delete duplicate elements from an array (http://www.c4learn.com/c-programs/to-delete-

duplicate-elements-in-array.html)

C Program to Add Two Numbers Using Pointer ! (http://www.c4learn.com/c-programs/add-two-

numbers-using-pointer.html)

C Program to Read integers into an array and Reversing them using Pointers

C Program to Find Length of the String using Pointer (http://www.c4learn.com/c-programs/c-program-

to-nd-length-of-the-string-using-pointer.html)

C Program to Implement Stack Operations Using Array (http://www.c4learn.com/c-programs/c-program-

(http://www.c4learn.com/c-
to-implement-stack-operations-using-array.html)
programs/)
C Program to Count number of words,digits,vowels using pointers (http://www.c4learn.com/c-

programs/c-program-to-count-number-of-wordsdigitsvowels-using-pointers-in-c-programming.html)

C Program to Compute sum of the array elements using pointers ! (http://www.c4learn.com/c-

programs/c-program-to-compute-sum-of-the-array-elements-using-pointers.html)

C Program to Perform Stack Operations Using Pointer ! (http://www.c4learn.com/c-programs/c-

program-to-perform-stack-operations-using-pointer.html)

C Program to Swap Two Numbers / Variables using Pointer (http://www.c4learn.com/c-

programs/interchanging-values-of-two-variables.html)

C Program for binary search on array using recursion (http://www.c4learn.com/c-programs/c-program-

binary-search-array-using-recursion.html)

C Program to Read integers into an array and Reversing


them using Pointers

http://www.c4learn.com/cprograms/cprogramusingpointersreadarrayofintegersandreverseit.html 2/8
9/26/2016 CProgramtoReadintegersintoanarrayandReversingthemusingPointers1DArrayPrograms,PointerProgramsc4learn.com

PlayRummy&WinBIG
Replay
GET

Iwon
1500
IwonaniPadina
80,000in
IwonaGoaTripby
WelcomeBonus
RummyTournament
RummyContest!
playingRummy
PlayRummyNow
ChandraMouli
LakshmiKala
RamaChandra
Kasargod,Kerala
Vadakara,Kerala
Hyderabad,AP

T&C

Write a C program using pointers to read in an array of integers and print its
elements in reverse order.

#include<stdio.h>
#include<conio.h>
#define MAX 30
(http://www.c4learn.com/c-

void main() {
programs/)
int size, i, arr[MAX]
int *ptr
clrscr()

ptr = &arr[0]

printf("\nEnter the size of array : ")
scanf("%d", &size)

printf("\nEnter %d integers into array: ", size)
for (i = 0 i < size i++) {
scanf("%d", ptr)
ptr++
}

ptr = &arr[size - 1]

printf("\nElements of array in reverse order are :")

for (i = size - 1 i >= 0 i--) {
printf("\nElement%d is %d : ", i, *ptr)
ptr--
}

getch()
}

http://www.c4learn.com/cprograms/cprogramusingpointersreadarrayofintegersandreverseit.html 3/8
9/26/2016 CProgramtoReadintegersintoanarrayandReversingthemusingPointers1DArrayPrograms,PointerProgramsc4learn.com

Output :

Enter the size of array : 5


Enter 5 integers into array : 11 22 33 44 55
Elements of array in reverse order are :
Element 4 is : 55
Element 4 is : 44
Element 4 is : 33
Element 4 is : 22
Element 4 is : 11

Program to read integers into an array and reversing them using pointers
Explanation :

1. We have declared one pointer variable and one array.

int size,i,arr[MAX]
int *ptr

2. Address of rst element of array is stored inside pointer variable.

(http://www.c4learn.com/c-
ptr=&arr[0]
programs/)
3. Accept Size of an Array.

printf("Enter the size of array : ")


scanf("%d",&size)

4. Now we have accepted element one by one using for loop and scanf statement .

printf("\nEnter %d integers into array: ", size)


for (i = 0 i < size i++) {
scanf("%d", ptr)
ptr++
}

5. Increment pointer variable (http://www.c4learn.com/pointer-arithmatics-incrementing-

pointer-variable-in-c-programming.html) so that it will then point to next element of array.

6. After accepting all elements store address of last element inside pointer variable.

ptr=&arr[size-1]

7. Again using reverse for loop and printf statement print an array.

for(i=size-1i>=0i--) {

http://www.c4learn.com/cprograms/cprogramusingpointersreadarrayofintegersandreverseit.html 4/8
9/26/2016 CProgramtoReadintegersintoanarrayandReversingthemusingPointers1DArrayPrograms,PointerProgramsc4learn.com

printf("nElement%d is %d :",i,*ptr)
ptr--
}

Gmail for Work


Look more professional with
custom Gmail from Google

SponsoredLinks

BaracksWorstNightmare!MaliaObamaCaughtPARTYINGInAmsterdam
RadarOnline
(http://www.c4learn.com/c-
programs/)

BeaRummySuperstarNow!BeaRummySuperstarToday
JungleeRummy

RenewyourCarInsuranceIn3EasySteps.
QuickBima.com

Calculate:AreYouFinanciallyProtectedAgainstHospitalBills?
BigDecisions

4ReasonsYouArePayingTooMuchforCarInsurance
Coverfox

IndepthStockMarketNewsForYou

http://www.c4learn.com/cprograms/cprogramusingpointersreadarrayofintegersandreverseit.html 5/8
9/26/2016 CProgramtoReadintegersintoanarrayandReversingthemusingPointers1DArrayPrograms,PointerProgramsc4learn.com

2Comments www.c4learn.com
1 Login

Recommend 1 Share SortbyNewest

Jointhediscussion

qasim2yearsago
awesome
Reply Share

paventhan2yearsago
fantastic
Reply Share

Subscribe d AddDisqustoyoursiteAddDisqusAdd Privacy

(http://www.c4learn.com/c-
programs/)

http://www.c4learn.com/cprograms/cprogramusingpointersreadarrayofintegersandreverseit.html 6/8
9/26/2016 CProgramtoReadintegersintoanarrayandReversingthemusingPointers1DArrayPrograms,PointerProgramsc4learn.com

(http://www.c4learn.com/c-
programs/)

ProgrammingTutor...
LikePage 42klikes

Bethefirstofyourfriendstolikethis

Get in Touch!

Recent Programs

C Program to read the content of le using fgets (http://www.c4learn.com/c-programs/read-content-le-


using-fgets.html)

C Program to perform arithmetic operations on oat (http://www.c4learn.com/c-programs/perform-

http://www.c4learn.com/cprograms/cprogramusingpointersreadarrayofintegersandreverseit.html 7/8
9/26/2016 CProgramtoReadintegersintoanarrayandReversingthemusingPointers1DArrayPrograms,PointerProgramsc4learn.com

arithmetic-operations-on-oat.html)

C Program to perform arithmetic operations on integer (http://www.c4learn.com/c-programs/perform-


arithmetic-operations-integers.html)

C Program to count trailing zeros using bitwise operator (http://www.c4learn.com/c-programs/count-trailing-


zeros-using-bitwise-operator.html)

C Program to convert number to binary using bitwise operators (http://www.c4learn.com/c-


programs/convert-number-to-binary-using-bitwise-operators.html)

Copyright 2015. All Rights Reserved.

(http://www.c4learn.com/c-
programs/)

http://www.c4learn.com/cprograms/cprogramusingpointersreadarrayofintegersandreverseit.html 8/8

S-ar putea să vă placă și