100% Prog JNTUK (29-1-24) SET 1-9a: Using pointers, print elements if array in reverse order
#include <stdio.h>
void main ()
{
int i,arr[5],*ptr;
ptr=&arr[0];
for(i=0;i<5;i++)
{
printf ("\nenter element a[%d]:",i);
scanf("%d",ptr+i);
}
printf("\n printing the numbers in reverse order begins:");
while(i)
{
printf(" %2d",*(ptr+--i)); //ఈ లాజిక్ అవగతం చేసుకొనుట కీలకం
}
}
void main ()
{
int i,arr[5],*ptr;
ptr=&arr[0];
for(i=0;i<5;i++)
{
printf ("\nenter element a[%d]:",i);
scanf("%d",ptr+i);
}
printf("\n printing the numbers in reverse order begins:");
while(i)
{
printf(" %2d",*(ptr+--i)); //ఈ లాజిక్ అవగతం చేసుకొనుట కీలకం
}
}
తెరమీద
enter element a[0]:1
enter element a[1]:3
enter element a[2]:5
enter element a[3]:7
enter element a[4]:9
printing the numbers in reverse order begins: 9 7 5 3 1
enter element a[1]:3
enter element a[2]:5
enter element a[3]:7
enter element a[4]:9
printing the numbers in reverse order begins: 9 7 5 3 1
-------------------------------------
#include <stdio.h>
void main ()
{
int i,arr[5],*ptr;
ptr=&arr[0];
for(i=0;i<5;i++)
{
printf ("\nenter element a[%d]:",i);
scanf("%d",ptr+i);
}
printf("\n printing the numbers in reverse order begins:");
while(i)
{
printf(" %2d",*(ptr+--i));
}
printf("\n printing the numbers in actual order begins:");
do
{
printf(" %2d",*(ptr+i++));
}while(i<5);
}
void main ()
{
int i,arr[5],*ptr;
ptr=&arr[0];
for(i=0;i<5;i++)
{
printf ("\nenter element a[%d]:",i);
scanf("%d",ptr+i);
}
printf("\n printing the numbers in reverse order begins:");
while(i)
{
printf(" %2d",*(ptr+--i));
}
printf("\n printing the numbers in actual order begins:");
do
{
printf(" %2d",*(ptr+i++));
}while(i<5);
}
తెరమీద
enter element a[0]:1
enter element a[1]:3
enter element a[2]:5
enter element a[3]:8
enter element a[4]:2
printing the numbers in reverse order begins: 2 8 5 3 1
printing the numbers in actual order begins: 1 3 5 8 2
enter element a[0]:1
enter element a[1]:3
enter element a[2]:5
enter element a[3]:8
enter element a[4]:2
printing the numbers in reverse order begins: 2 8 5 3 1
printing the numbers in actual order begins: 1 3 5 8 2
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.