Write a program to find the largest element within an integer array using pointers.
CODING:
#include <stdio.h>
#include<conio.h>
void main()
{
int num[10]={1,2,3,4,5,10,6,7,8,9},a,b,temp;
int *ptr;
clrscr();
ptr=num;
for(a=0;a<10;a++)
for(b=a+1;b<10;b++)
if(*(ptr+a)<*(ptr+b))
{
temp=*(ptr+b);
*(ptr+b)=*(ptr+a);
*(ptr+a)=temp;
}
printf("\nLargest number in array : %d",*ptr);
getch();
}
CODING:
#include <stdio.h>
#include<conio.h>
void main()
{
int num[10]={1,2,3,4,5,10,6,7,8,9},a,b,temp;
int *ptr;
clrscr();
ptr=num;
for(a=0;a<10;a++)
for(b=a+1;b<10;b++)
if(*(ptr+a)<*(ptr+b))
{
temp=*(ptr+b);
*(ptr+b)=*(ptr+a);
*(ptr+a)=temp;
}
printf("\nLargest number in array : %d",*ptr);
getch();
}
Comments
Post a Comment