kiem tra xem co k so lap thanh cap so cong ko
/*nhap dayva so k,kiem tra xem co k so dung canh nhau lap thanh cap so cong hay ko*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void nhap(float a[],int n)
{
for(i=0;i<n;i++)
{
printf("nhap phan tu thu %d : ",i);
scanf("%f",&a[i]);
}
}
int inday(float a[],int bd,int k)
{
for(i=bd;i<(bd+k);i++)
printf("%.3f ",a[i]);
}
int csc(float a[],float d,int bd,int k)
{
int i,y=0;
for(i=bd;i<=(bd+k);i++)
if(fabs(d-(a[i+1]-a[i]))<=0.0001)
y++;
if(y==k-1)return 1;
return 0;
}
int main()
{
float a[100];
int n,k;
printf("nhap so phan tu cua day: ");scanf("%d",&n);
nhap(a,n);
while((k<3)||(k>n))
{
printf("nhap vao so k: ");scanf("%d",&k);
}
printf("day vua nhap la:
");
inday(a,0,n);
int t=0,i=0;
do
{
float d=(a[i+1]-a[i]);
if(csc(a,d,i,k))
{ printf("
day con gom %d phan tu lap thanh cap so cong la:
",k);
inday(a,i,k);
t=t+1;
}
i++;
}while(i<(n-k));
if(t==0)
printf("
khong co day con gom %d phan tu lap thanh cap so cong",k);
getch();
return 0;
}
Bạn đang đọc truyện trên: AzTruyen.Top