Search This Blog

Monday 29 August 2011

C-PRAOGRAMM to find the arithmetic progression


include<stdio.h>
#include<conio.h>
main()
{
int t1,t2,tn,a,d,n;
clrscr();
printf("enter the value for t1\n");
scanf("%d",&t1);
if(t1<1)
{
printf("enter the value a\n");
scanf("%d",&a);
printf("enter the value for d\n");
scanf("%d",&d);
}
else
{
printf("enter the value for t2\n");
scanf("%d",&t2);
}
printf("enter the value for n\n");
scanf("%d",&n);
if((t1!=0)&&(t2!=0))
{
d=t2-t1;
tn=t1+(n-1)*d;
}
else
{
tn=a+(n-1)*d;
}
printf("\nt%d=%d",n,tn);
getch();
}

No comments:

Post a Comment