write a program to display the array elements in reverse
order in c language

Answer Posted / arpit dhandhania

Both the solution above is wrong...

Answer #1: It will input an extra element in array coz array is starting from 0 and goes till n so total elements n+1

Answer #2: C Automatically starts array from 0 index and not 1 if not programmed otherwise and in the given program we are starting the loop from 1

Solution

void main()
{
int a[30],n;
scanf("%d",&n);

for(int i=0;i<n;i++)
scanf("%d",&a[i]);

for(i=n-1;i>=0;i--)
printf("%d",a[i]);

}
}

Is This Answer Correct ?    65 Yes 39 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What does static variable mean in c?

656


Is there any possibility to create customized header file with c programming language?

629


What is the difference between declaring a variable and defining a variable?

726


What is the return type of sizeof?

598


Why is python slower than c?

609






What would happen to X in this expression: X += 15; (assuming the value of X is 5)

1308


what is different between auto and local static? why should we use local static?

647


Explain function?

665


Do you have any idea how to compare array with pointer in c?

608


What are the uses of null pointers?

594


Why is c fast?

611


What are header files? What are their uses?

642


Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)

1866


What is #define in c?

624


What is typedef example?

619