Monday, May 6, 2013

Sum of serise: The natural logarithm can be approximated by the following series.

#include<stdio.h>
void main()
{
float x,a,b=1,sum=0;
printf("Enter the value of X: ");
scanf("%f"&x);
a=(x-1)/x;
for(int k=1;k<=7;k++)
{
b=b*a;
sum+=b;
}
sum-=a;
sum/=2;
sum+=a;
printf("\n\n\t The Natural algorithm of %f=%f",x,sum);
return 0;
}

Pattern: printf pattern./ print following pattern

Write a program which will print following pattern...

#include<stdio.h>
#include<math.h>
void main()
{
int i,j,k=1,l=0;
for(i=0;i<4;i++)
{
for(j=3;j<4;j++)
{
k=i-abs(j);
if(k<0||(k%2)!=0)
printf("\t");
else
printf("%8d",++l);
}
printf("\n");
}
return 0;
}