Jacobi itterative and gauss seidal method to solve roots
this is a program from numerical to calculate the root ofthe given system ,it will check its conditions and then perform the
operation on that system,esle it will tell u that system is not diagonally dominent
,,,,in this program the functions used can be used in other program ,,#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<iomanip.h>
float a1[4],a2[4],a3[4]; /* Array declaration */
void show(); /* function declaration
*/void getdata(float [],float [],float []); /* // // //
*/void display(float [],float [],float []); /* // // //
*/int diagonally();void swap(float [],float []); /* // // //
*/void jacobi(float [],float [],float []); /* // // //
*/void gauss(float [],float [],float []);
void answer();/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*//*....................MAIN FUNCTION OF METHOD............*/void main() /* main function definition
*/ {int count=4; /* { main function body}
*/clrscr();
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;
cout<<"..................THIS IS VALID ONLY FOR JACOBI ITTERATIVEMETHOD............."<<endl;
cout<<"______________________________________________________________________________"<<endl;
show(); /* function calling */ getdata(a1,a2,a3); /* function calling */clrscr();
cout<<endl<<endl;
display(a1,a2,a3); /* function calling */ count=diagonally(); /* function calling */ switch (count) { case 0: { answer(); /* function calling */ break;}
case 2: {display(a1,a2,a3); answer(); /* function calling */ break;}
default: { cout<<"SORRY;YOUR SYSTEM IS NOT DIAGONALLY DOMINENT"; break;}
}
getch();
}
////////////////////////Function To CheckDiagonality////////////////////////int diagonally() { int f=4,g=4 ,h=4; int count=0; float temp[4]; if(fabs(a1[0])<(fabs(a1[1])+fabs(a1[2]))) {count++; f=1;} if(fabs(a2[1])<(fabs(a2[0])+fabs(a2[2]))) {count++; g=2;} if(fabs(a3[2])<(fabs(a3[0])+fabs(a3[1]))) {count++; h=3;} if(f==1&&g==2&&h==4) swap(a1,a2); /* function calling */ if(f==1&&h==3&&g==4) swap(a1,a3); /* function calling */ if(g==2&&h==3&&f==4) swap(a2,a3); /* function calling */ return(count);}
////////////////////////////Function for jacobi itterativemethod/////////////////////////void jacobi(float a[],float b[],float c[]) /*function definition */
{ float temp[3];long float j1,j2,j3;
cout<<endl<<"please enter the initial guess:"<<endl; cout<<endl<<"X(1) =";cin>>j1;
cout<<endl<<"X(2) =";cin>>j2;
cout<<endl<<"X(3) =";cin>>j3;
cout<<"-----------------------------------------------------------------------";
cout<<":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::";
cout<<"_______________________________________________________________________";
cout<<endl<<endl<<"iterrations #"<<" "<<" X(1)"<<"
X(2)"<<" X(3)"; cout<<endl<<" 0"<<setw(17)<<j1<<setw(15)<<j2<<setw(14)<<j3;cout<<endl;
for(int s=1;s<=20;s++)
{temp[0]=j1;temp[1]=j2;temp[2]=j3;
j1=(a[3]-a[1]*temp[1]-a[2]*temp[2])/a[0];
j2=(b[3]-b[0]*temp[0]-b[2]*temp[2])/b[1];
j3=(c[3]-c[0]*temp[0]-c[1]*temp[1])/c[2];
cout<<" "<<s<<setw(17)<<j1<<setw(15)<<j2<<setw(14)<<j3<<endl; if(j1==temp[0]&&j2==temp[1]&&j3==temp[2]) break;}
}
//////////////////////////Function OfSwaping////////////////////////////////////void swap(float a[],float b[]) /* function definition */
{ float temp[4];cout<<"--------------------------------------------------------------------------------"<<endl;
Calculator - A division, multiplication, adding, subtracting program.
#include<iostream>
#include<string>
using namespace std;
float mult(float num1,float num2);
float add(float num1,float num2);
float sub(float num1,float num2);
float divide(float num2,float num2);
int main(){ int choice; float num1,num2; cout<<" CALCULATOR "<<endl; cout<<" Make a selction:"<<endl; cout<<" 1.Division"<<endl; cout<<" 2.Adding"<<endl; cout<<" 3.Subtraction"<<endl; cout<<" 4.multiplication"<<endl; cout<<"YOUR CHIOCE IS: ";
cin>>choice;
switch(choice){ case 1: cout<<"Please enter the two numbers you want todivide, divisor first!: ";
cin>>num1>> num2;
cin.ignore();
cout<<""<<num1<<"/"<<num2<<"="<<divide(num1,num2)<<endl;
break; case 2: cout<<"Please enter the two numbers you
want to add: ";
cin>>num1>> num2;
cin.ignore();
cout<<""<<num1<<"+"<<num2<<"="<<add(num1,num2)<<endl;
break; case 3: cout<<"Please enter the
two numbers you want to subtract, The number you want to subtract from
first!: ";
cin>>num1>> num2;
cin.ignore();
cout<<""<<num1<<"-"<<num2<<"="<<sub(num1,num2)<<endl;
break; case 4:cout<<"Pleaseenter the two numbers you want to multiply: ";
cin>>num1>>
num2;
cin.ignore();
cout<<""<<num1<<"*"<<num2<<"="<<mult(num1,num2)<<endl;
break;default:cout<<"Invalid Entry!, BYE!!!"<<endl;cin.ignore();
break;}
cin.ignore();
return 0;}
float mult(float num1,float num2){
return (num1*num2);}
float add(float num1,float num2){
return (num1+num2);}
float sub(float num1,float num2){
return (num1-num2);}
float divide(float num1,float num2){
return (num1/num2);}
Program to find your Day of Birth given Date of Birth
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
main()
{clrscr();
int d,m,y,year,month,day,i,n; printf("Enter how many times you want to run this program : "); scanf("%d",&n); for(i=1;i<=n;i++) { printf("Enter the date : ");
scanf("%d%d%d",&d,&m,&y); if( d>31 || m>12 || (y<1900 || y>=2000) ) { printf("INVALID INPUT
");
getch();
exit(0);
}
year = y-1900;
year = year/4;
year = year+y-1900;
switch(m) { case 1: case 10:month = 1;
break; case 2: case 3: case 11:month = 4;
break; case 7: case 4:month = 0;
break; case 5:month = 2;
break; case 6:month = 5;
break; case 8:month = 3;
break; case 9: case 12:month = 6;
break;}
year = year+month;
year = year+d;
day = year%7;
switch(day) { case 0: printf("Day is SATURDAY
");
break; case 1: printf("Day is SUNDAY
");
break; case 2: printf("Day is MONDAY
");
break; case 3: printf("Day is TUESDAY
");
break; case 4: printf("Day is WEDNESDAY
");
break; case 5: printf("Day is THURSDAY
");
break; case 6: printf("Day is FRIDAY
");
break;}
}
getch();
return 0;}
درباره ما
اطلاعات کاربری
نویسندگان
آمار سایت
کدهای اختصاصی


طراحي وبسايت
دانلود کتاب طراحی الگوریتم CLRS به همراه حل مسائل