Tuesday, April 26, 2011

C Program to print local Date and Time

#include <STDIO.H> 
#include <TIME.H> 
int current_day(void) 
{
 struct tm *local; 
  time_t t; 
 t = time(NULL); 
 local = localtime(&t); 
 return local->tm_wday; 
} 
int main(int argc, char *argv[]) 
{ 
  printf("Today: %d\n", current_day()); 
  exit(0); 
}
 

Friday, April 1, 2011

C Program for bisection method........!


#include[stdio.h] 
#include[math.h] 
#define epsln 1e-6 
void main() 
{ 
double g1,g2,g,v,v1,v2,dx; 
int found,converged,i; 
found=0; 
printf(" enter the first guess\n"); 
scanf("%lf",&g1); 
v1=g1*g1*g1-15; 
printf("value 1 is %lf\n",v1); 


while (found==0) 
{ 
printf("enter the second guess\n"); 
scanf("%lf",&g2); 
v2=g2*g2*g2-15; 
printf(" value 2 is %lf\n",v2); 
if (v1*v2>0) 
{found=0;} 
else 
found=1; 
} 
printf("right guess\n"); 
i=1; 


while (converged==0) 
{ 
printf("\n iteration=%d\n",i); 
g=(g1+g2)/2; 
printf("new guess is %lf\n",g); 
v=g*g*g-15; 
printf("new value is%lf\n",v); 
if (v*v1>0) 
{ 
g1=g; 
printf("the next guess is %lf\n",g); 
dx=(g1-g2)/g1; 
} 
else 
{ 
g2=g; 
printf("the next guess is %lf\n",g); 
dx=(g1-g2)/g1; 
} 
if (fabs(dx)< epsln )
{
converged=1;
} 
i=i+1; 
} 
printf("\nth calculated value is %lf\n",v); 
}