0% found this document useful (0 votes)
6 views7 pages

Reverse Array Practice Code

Assignment

Uploaded by

077bce187.ujwal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views7 pages

Reverse Array Practice Code

Assignment

Uploaded by

077bce187.ujwal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Array Practice Questions:-

1. #include<stdio.h>

int reverse(int *,int);

int main()

int a[5],i;

printf("Enter the numbers:");

for(i=0;i<5;i++)

scanf("%d",&a[i]);

printf("The numbers in array are:\n");

for(i=0;i<5;i++)

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

printf("The reverse array is:\n");

reverse(&a[4],5);

return 0;

int reverse(int *p,int size)

int i;

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

printf("%d\n",*p);

p--;
Array Practice Questions:-

2. #include <stdio.h>

int main() {

float a[5];

int i,element=0,position=0;

printf("Input the 5 members of the array:\n");

for(i = 0; i < 5; i++) {

scanf("%f", &a[i]);

printf("The values of array are:\n");

for(i = 0; i < 5; i++) {

printf(" %.0f\n", a[i]);

printf("Enter the element whose position is to be found: "); //printing a message for user

scanf("%d", &element); //taking element to be found from user

for(i = 0; i < 5; i++) //again looping through array

if(a[i] == element) //checking if the element at specific position is equal to the element given by
user

{ //if condition is true

position = i+1; //saving the position of element in position variable

break;
Array Practice Questions:-

printf("The position of %d in array is: %d", element, position); //printing the element and its position

return 0;

3. #include<stdio.h>

void ascending(int *,int);

void descending(int *,int);

int main()

int a[5],i;

printf("Enter the numbers in array:\n");

for(i=0;i<5;i++)

scanf("%d",&a[i]);

printf("The numbers in ascending order are:\n");

ascending(&a[0],5);

printf("The numbers in descending order are:\n");

descending(&a[0],5);

return 0;

void ascending(int *a,int size){

int i,j,tmp;

for(i=0;i<size;i++)

for(j=i+1;j<size;j++)
Array Practice Questions:-

if( *(a+i) > *(a+j))

tmp = *(a+i);

*(a+i) = *(a+j);

*(a+j) = tmp;

for(i=0;i<size;i++){

printf("%d\n",*(a+i));

void descending(int *a, int n)

int i, j, temp;

for(i=0;i< n;i++)

for(j=i+1;j< n;j++)

if(*(a+i)< *(a+j))

temp = *(a+i);

*(a+i) = *(a+j);

*(a+j) = temp;

}
Array Practice Questions:-

for(i=0;i<n;i++){

printf("%d\n",*(a+i));

}
Array Practice Questions:-
Array Practice Questions:-

You might also like