You are on page 1of 1

LAB PROGRAM 2 /*Program to find largest element of an array using pointers*/ #include<stdio.h> #include<conio.

h>

void main() { float a[10],big; int i,n,pos; clrscr(); /*Read the size of array*/ printf("Enter the size of array:\t"); scanf("%d",&n); /*Read the elements of array*/ printf("Enter %d elements:\n"); for(i=0;i<n;i++) { scanf("%f",a+i); } printf("The array elements are:\n\n"); printf("-------------------\n"); for(i=0;i<n;i++) { printf("\n\t%f",*(a+i)); } big=*(a+0); /* assigning the first element to big */ pos=0; /* assigning zero to pos to indicate zeroth position */

for(i=0;i<n;i++) { if(*(a+i)>big) { big=*(a+i); pos=i; } } printf("\n\nLargest element is %f at position %d",big,pos+1); getch(); }

You might also like