C program to print or find the greatest difference between two array elements.
In this tutorial we will solve a problem that find maximum difference between two array elements.
Here we will write a c program source code to print highest difference in an array.
This program will accept the range or size of an array that entered by user through the keyboard.
After it we will enter the elements of this array.
After these steps compiler check and execute the conditions and print greatest difference between two array elements.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,num,temp,maxDiff=0;
int a[50];
clrscr();
printf("\n ENTER THE SIZE OF ELEMENTS IN THIS ARRAY :\n ");
scanf("%d",&num);
printf("\n ENTER NUMBERS OF ARRAY :\n ");
for(i=0;i<num;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<num;i++)
{
for(j=i+1;j<num;j++)
{
if(a[j]-a[i]>maxDiff)
{
maxDiff=a[j]-a[i];
}
}
}
printf("\n MAXIMUM DIFFERENCE IS :\n %d\n",maxDiff);
getch();
}
In this tutorial we will solve a problem that find maximum difference between two array elements.
Here we will write a c program source code to print highest difference in an array.
This program will accept the range or size of an array that entered by user through the keyboard.
After it we will enter the elements of this array.
After these steps compiler check and execute the conditions and print greatest difference between two array elements.
C PROGRAM CODE
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,num,temp,maxDiff=0;
int a[50];
clrscr();
printf("\n ENTER THE SIZE OF ELEMENTS IN THIS ARRAY :\n ");
scanf("%d",&num);
printf("\n ENTER NUMBERS OF ARRAY :\n ");
for(i=0;i<num;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<num;i++)
{
for(j=i+1;j<num;j++)
{
if(a[j]-a[i]>maxDiff)
{
maxDiff=a[j]-a[i];
}
}
}
printf("\n MAXIMUM DIFFERENCE IS :\n %d\n",maxDiff);
getch();
}
OUTPUT:
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
I read your comment, I am ready to share your link on my site, but will you give me money in return and if so how many? Reply soon
ReplyDelete