Write a program to find the smallest and largest element in
a given array in c language
Answer Posted / chandrashekhar
# include<stdio.h>
void main()
{
int a[10];
int max=0,min=0,n,i=0;
printf("enter array size");
scanf("%d",&n);
printf("enter elements");
for( i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
//mini num
min=a[i];
for(int i=1;i<n;i++)
{
if(min>a[i])
{
min=a[i++];
}
}
//max num
max=a[i];
for(int i=1;i<n;i++)
{
if(max<a[i])
{
max=a[i++];
}
}
printf( "min=%d max=%d",min,max);
getch();
}
| Is This Answer Correct ? | 21 Yes | 17 No |
Post New Answer View All Answers
Why do some versions of toupper act strangely if given an upper-case letter?
How do you initialize pointer variables?
How the c program is executed?
What does *p++ do? What does it point to?
What is a const pointer?
Write a program to print "hello world" without using a semicolon?
Why isnt any of this standardized in c?
Can we change the value of #define in c?
What is masking?
Explain how can you check to see whether a symbol is defined?
How can you access memory located at a certain address?
What is the value of a[3] if integer a[] = {5,4,3,2,1}?
Can math operations be performed on a void pointer?
write a program that will open the file, count the number of occurences of each word in the the complete works of shakespeare. You will then tabulate this information in another file.
What is a pointer on a pointer in c programming language?