Question-Find the smallest number in an array using pointers.
Solution-
An easy question.it's totally up to you what size of array you want to choose. This type of question would help you in next problems. so, try to grasp the concept . let's look up the solution.
#include <stdio.h>
#include <stdlib.h>
#define m 10
int main()
{
int arr[m];
int i;
printf("Enter the elements of the array\n");
for(i=0;i<=m-1;i++)
scanf("%d",&arr[i]);
finder(arr);
getch();
}
finder(int *arr[m])
{
int i,j;
int k;
for(i=0;i<=m-1;i++)
{
for(j=i+1;j<=m-1;j+=1)
{
if(*(arr+i)>*(arr+j))
{
k=*(arr+i);
*(arr+i)=*(arr+j);
*(arr+j)=k;
}
}
}
printf("The smallest number of the array is %d",*arr);
}
Solution-
An easy question.it's totally up to you what size of array you want to choose. This type of question would help you in next problems. so, try to grasp the concept . let's look up the solution.
#include <stdio.h>
#include <stdlib.h>
#define m 10
int main()
{
int arr[m];
int i;
printf("Enter the elements of the array\n");
for(i=0;i<=m-1;i++)
scanf("%d",&arr[i]);
finder(arr);
getch();
}
finder(int *arr[m])
{
int i,j;
int k;
for(i=0;i<=m-1;i++)
{
for(j=i+1;j<=m-1;j+=1)
{
if(*(arr+i)>*(arr+j))
{
k=*(arr+i);
*(arr+i)=*(arr+j);
*(arr+j)=k;
}
}
}
printf("The smallest number of the array is %d",*arr);
}
No comments:
Post a Comment