Monday, October 26, 2009

PROGRAM TO FIND THE SOLUTION OF ALGEBRIC EQUATIONS USING GAUSS-SEIDEL ITERATIVE METHOD

// SHUAIB SARKAR
// PROGRAM TO FIND THE SOLUTION OF
// ALGEBRIC EQUATIONS USING GAUSS-SEIDEL ITERATIVE METHOD

#include"stdio.h"
#include"conio.h"
#include"math.h"
#define FUNCX(y,z) (17-y+2*z)/20
#define FUNCY(x,z) (-18-3*x+z)/20
#define FUNCZ(x,y) (25-2*x+3*y)/20
void main()
{
float x1,y1,z1;
float a,b,c;
float x2,y2,z2;
int itr=1;
clrscr();
printf("\n\t\t\t GAUSS - SEIDEL ITERATION METHOD");
printf("\n\t\t\t=================================\n");
printf("\n\t\t\tValue Of X\t Value of Y\tValue of Z");
printf("\n======================================================");
x1=y1=z1=0;
do
{
a=FUNCX(y1,z1);
x2=x1;
x1=a;
b=FUNCY(x1,z1);
y2=y1;
y1=b;
c=FUNCZ(x1,y1);
z2=z1;
z1=c;
printf("\n Iterration : %d \t %f\t %f\t%f ",itr++,a,b,c);
}while(a!=x2 && b!=y2 && c!=z2);
printf("\n =====================================================");
printf("\n SOLUTION IS : \n\n X = %f \t Y= %f\t Z= %f",a,b,c);
getch();
}

Saturday, October 24, 2009

PROGRAM TO FIND THE ROOT OF AN EQUATION USING REGULA-FALSE METHOD

// SHUAIB SARKAR
// PROGRAM TO FIND THE ROOT OF AN EQUATION
// USING REGULA-FALSE METHOD

#include"stdio.h"
#include"conio.h"
#include"math.h"
#define FUNC(x) x*x*x-4*x-9

void roots(float x1,float x2)
{
int itr=1;
char trmtr='F';
float a,F1,F2;
do{
F1=FUNC(x1);
F2=FUNC(x2);
a=(x1*F2-F1*x2)/(F2-F1);
if(FUNC(a)<0) x1=a; else x2=a; printf("\n Iterration : %d \t\t %f\t\t %f ",itr,a,FUNC(a)); if(fabs(FUNC(a))<0.0001) { printf("\n=============================================================="); printf("\n Root is : %6.4f\n",a); trmtr='T'; } else { trmtr='F'; itr++; } }while(trmtr=='F'); } void main() { float x1,x2; clrscr(); printf("\n\t\t\t\t REGULA-FALSE METHOD\n"); printf("\n Enter the initial values : "); scanf("%f%f",&x1,&x2); if(FUNC(x1)<0 && FUNC(x2)>0)
{
printf("\n\t\t\t ITERATIONS INVOLVED \n");
printf("\n\t\t\t Aprox Root(s) \t Value of Function\n");
printf("\n===============================================");
roots(x1,x2);
}
else
{
printf("\n ROOTS of the Function don't lie between %3.0f and %3.0f",x1,x2);
getch();
exit(0);
}
getch();
}

Sunday, October 18, 2009

Calender of a month of the current year....

// SHUAIB SARKAR

// PROGRAM TO DISPLAY THE CALENDER OF A GIVEN MONTH
// OF CURRENT YEAR

#include"stdio.h"
#include"conio.h"
#include"dos.h"
#include"math.h"

void main()
{
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
char *chmon[]={"JANUARY","FEBRUARY","MARCH","APRIL","MAY"
,"JUNE","JULY","AUGUST","SEPTEMBER","OCTOER",
"NOVEMBER","DECEMBER"};
int cal,mth,year,leap;
int i,day,odday=1,date;
struct date d;
clrscr();
getdate(&d);
if(d.da_year%4==0)
mon[1]=29;
do{
printf("\n Enter the Month (1-12) : ");
scanf("%d",&mth);
if(mth<=0 || mth>12)
{
textcolor(5);
cprintf("\n PLEASE Enter the correct data");
textcolor(7);
}
}while(mth<=0 || mth>12);
year=d.da_year;
for(i=0;i<(mth-1;i++)< p="">
{
odday+=mon[i]%7;
}
year-=2000;
year--;
leap=year/4;
leap+=year;
odday+=leap;
cal=odday%7;
day=cal+1;
printf("\n\n\t\t CALANDER FOR %s %d\n",chmon[mth-1],d.da_year);
printf("\n\t====================================================\n\n");
printf("\t SUN\tMON\tTUE\tWED\tTHU\tFRI\tSAT\n\n");
if(cal==1)
printf("\t");
if(cal==2)
printf("\t\t");
if(cal==3)
printf("\t\t\t");
if(cal==4)
printf("\t\t\t\t");
if(cal==5)
printf("\t\t\t\t\t");
if(cal==6)
printf("\t\t\t\t\t\t");
for(date=1;date<=mon[mth-1];date++)
{
printf("\t%3d",date);
if(day==7)
{
printf("\n\n");
day=0;
}
day++;
}
printf("\n\n\n");
getch();
}