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
how should functions be apportioned among source files?
what is use of malloc and calloc?
What should malloc() do? Return a null pointer or a pointer to 0 bytes?
Why is #define used?
Write a Program to find whether the given number or string is palindrome.
the process of defining something in terms of itself is called (or) in C it is possible for the functions to call themselves. A function called a) nested function b) void function c) recursive function d) indifinite function
Can 'this' pointer by used in the constructor?
How can variables be characterized?
1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.
What is wrong with this program statement?
Describe the steps to insert data into a singly linked list.
What is declaration and definition in c?
What are multibyte characters?
What does 2n 4c mean?
What is this pointer in c plus plus?