This code is giving incorrect answer in some inputs.If possible someone
correct it.
#include<stdio.h>
#include<conio.h>
static int SIZE=5;
void print(int *array);
int del(int *array,int i);
int decrement(int *array,int i);
void print(int *array)
{
printf("\n");
int i=0;
for(;i<SIZE;i++)
printf("%d\t",array[i]);printf("\n");
}
int del(int *array,int i)
{
int x=array[i];
for(;i<=SIZE-2;i++)
array[i-1]=array[i+1];
SIZE-=1;
return x;
printf("\nSize",SIZE);
}
int decrement(int *array,int i)
{ int c=0;
while(array[i]>array[i+1]){
c++;
array[i]=array[i]-1;
return c;
}
}
int main()
{
int i,j,array[SIZE],count=0,flag=0;
for(i=0;i<SIZE;i++)
scanf("%d",&array[i]);
while(!flag){
flag=1;
j=1;
i=0;
do{
if(array[i]>array[j]){
if((array[i]-array[j])>array[j])
count=del(array,j);
else
count=decrement(array,i);flag=0;
}
j++;i++;
}while(j<=SIZE);
}
print(array);
printf("\nTotal cost=%d",count);
getch();
return 0;
}
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.