From 9a87b8cb87dc2990e076a2db1d4b8ceabf74898a Mon Sep 17 00:00:00 2001 From: Thanga Ayyanar Date: Mon, 1 May 2017 17:43:34 +0530 Subject: [PATCH] Create Correct_the_arithmetic_series.c --- Correct_the_arithmetic_series.c | 75 +++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Correct_the_arithmetic_series.c diff --git a/Correct_the_arithmetic_series.c b/Correct_the_arithmetic_series.c new file mode 100644 index 0000000..a27ff1b --- /dev/null +++ b/Correct_the_arithmetic_series.c @@ -0,0 +1,75 @@ +Given a arithmetic series + +i/p:2 4 5 6 8 + here 5 is wrong term in series other number are in difference of 2 + +o/p: 5 + +#include +#include +int point=0; +void sort(int a[],int n){ //bubble sort algorithm to sort the given terms + int i,j,temp; + for(i=0;imax){ + point=i; + max=count; + t1=tdiff; + } + } + return t1; +} +int main(){ + + int n=1,i,f=0,*a=(int *)malloc(n*sizeof(int)),difference; + char c; + for(i=0;;i++){ + if(scanf("%d%c",&a[i],&c)==2){ + if(c=='\n') + break; + else + n++; + } + } + + sort(a,n); + + difference=find_difference(a,n); + + printf("The difference and index is %d %d\n",difference,point); + + if(point>1){ //if the first element is wrong term + printf("%d",a[0]); + return 0; + } + + for(i=1;i