등차 등비 수열 구하기
2010. 3. 25. 11:09ㆍ2010년/30계단1~2단계
등차 수열
예) 1 , 2 , 3 , 4 ... 공차: 1 1 , 3 , 5 , 7 .... 공차: 2

예) 1 , 2 , 4 , 8 , ... 공비: 2 2 , 6 , 18 , 54 , .. 공비: 3
입력
한 줄당 4 개의 수가 입력으로 주어진다. 네 개의 수는 등차 혹은 등비 수열이다.출력
원래 수열과 다음 항의 수를 출력한다.입출력 예
입력 1 2 3 4 출력 1 2 3 4 5 입력 1 2 4 8 출력 1 2 4 8 16 ----------------------
#include<stdio.h>
int main()
{
int ione;
int itwo;
int ithree;
int ifour;
int ibe;
int icha;
int iyou;
int itoo;
fprintf(stdout,"등차 등비 수열 4개를 입력하세요\n");
fscanf(stdin,"%d %d %d %d",&ione,&itwo,&ithree,&ifour);
icha=ifour-ithree;
ibe=ithree-itwo;
iyou=ifour/ithree;
itoo=ithree/itwo;
if(icha==ibe)
{
fprintf(stdout,"%d %d %d %d %d",ione,itwo,ithree,ifour,ifour+icha);
}
else if(iyou==itoo)
{
fprintf(stdout,"%d %d %d %d %d",ione,itwo,ithree,ifour,ifour*itoo);
}
return 0;
}