![]() | |
| |||||||
| Home | Register | Projects | Blogs | FAQ | Calendar | Search | Today's Posts | Mark Forums Read | Free Directory | Free DNSReport | Tags |
| Notices |
| Programming Discuss about the various programming languages (HTLM/PHP/ASP/C#/C++/Java etc..) |
building matricesThis is a discussion on "building matrices" within the Programming part of the Computer Security: Discussions section; Now what I want to show is a few algorithms on how to show my imagination on working with indices in matrices. This first algorithm looks like this : input : n=4 output : 2 3 5 7 37 41 43 11 ... |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| |||
| Now what I want to show is a few algorithms on how to show my imagination on working with indices in matrices. This first algorithm looks like this : input : n=4 output : 2 3 5 7 37 41 43 11 31 53 47 13 29 23 19 17 It is a coil out of numbers .Code: #include<iostream.h>
#include<stdio.h>
#include<iomanip.h>
void header();
int n,d,ok,b[100],i,k,j,x,a[20][20];
void main()
{ header();
cout<<"n=";cin>>n;
b[1]=2;
k=2;
x=3;
while(k<=n*n) { ok=1;
for(d=2;d<=x/2;d++) if(x%d==0) ok=0;
if(ok) b[k++]=x;
x++;
}
x=1;
for(k=1;k<=n/2+1;k++) { for(j=k;j<=n-k+1;j++) a[k][j]=b[x++];
for(i=k+1;i<=n-k+1;i++) a[i][n-k+1]=b[x++];
for(j=n-k;j>=k;j--) a[n-k+1][j]=b[x++];
for(i=n-k;i>k;i--) a[i][k]=b[x++];
}
for(i=1;i<=n;i++)
{ for(j=1;j<=n;j++) cout<<setw(2)<<a[i][j]<<" ";
cout<<endl;
}
}
void header()
{ printf("---------------------------------------------------------------\n");
printf("Autor : fl0 fl0w \n");
printf("flo[underscore]flow[underscore]supremacy[at]yahoo[dot]com\n");
printf("---------------------------------------------------------------\n");
} n=4 m=3 a[1][1]=1 a[1][2]=2 a[1][3]=3 a[2][1]=4 a[2][2]=5 a[2][3]=6 a[3][1]=7 a[3][2]=8 a[3][3]=9 a[4][1]=10 a[4][2]=11 a[4][3]=12 Matricea este 1 2 3 4 5 6 7 8 9 10 11 12 Conturul matricei este 1 2 3 6 9 12 11 10 7 4 Yep you guest good it's the outline of the matrix. Code: #include<iostream.h>
#include<stdio.h>
int n,m,i,j,a[10][10];
// function prototype
void header();
void main()
{ header();
cout<<"n=";cin>>n;
cout<<"m=";cin>>m;
for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{ cout<<"a["<<i<<"]["<<j<<"]=";
cin>>a[i][j];
}
cout<<"Matricea este "<<endl;
for(i=1;i<=n;i++)
{ for(j=1;j<=m;j++) cout<<a[i][j]<<" ";
cout<<endl;
}
cout<<"Conturul matricei este "<<endl;
for(j=1;j<=m;j++) cout<<a[1][j]<<" ";
for(i=2;i<=n;i++) cout<<a[i][m]<<" ";
for(j=m-1;j>=1;j--) cout<<a[n][j]<<" ";
for(i=n-1;i>=2;i--) cout<<a[i][1]<<" ";
cout<<endl;
}
void header()
{ printf("---------------------------------------------------------------\n");
printf("Autor : fl0 fl0w \n");
printf("flo[underscore]flow[underscore]supremacy[at]yahoo[dot]com\n");
printf("---------------------------------------------------------------\n");
} a=5 b=-2 c=-3 Ecuatia are radacini reale si distincte x1=1 x2=-0.6 Code: #include<iostream.h>
#include<stdio.h>
#
#include<math.h>
#
void header();
int a,b,c,d;
#
float x,x1,x2;
#
void main()
#
{ header();
cout<<"a=";cin>>a;
#
cout<<"b=";cin>>b;
#
cout<<"c=";cin>>c;
#
if(a==0) if(b==0) if(c==0) cout<<"Ecuatie nedeterminata"<<endl;
#
else cout<<"Ecuatie imposibila "<<endl;
#
else { x=(float)-c/b;
#
cout<<"Ecuatie de gradul intai ,x="<<x<<endl;
#
}
#
else { d=b*b-4*a*c;
#
if(d<0) cout<<"Ecuatia are radacini complexe "<<endl;
#
else if(d==0) { x=(float)-b/(2*a);
#
cout<<"Ecuatia are radacini reale si egale,x1=x2="<<x<<endl;
#
}
#
else { x1=(float)(-b+sqrt(d))/(2*a);
#
x2=(float)(-b-sqrt(d))/(2*a);
#
cout<<"Ecuatia are radacini reale si distincte"<<endl;
#
cout<<"x1="<<x1<<endl;
#
cout<<"x2="<<x2<<endl;
#
}
#
}
#
#
}
void header()
{ printf("---------------------------------------------------------------\n");
printf("Autor : fl0 fl0w \n");
printf("flo[underscore]flow[underscore]supremacy[at]yahoo[dot]com\n");
printf("---------------------------------------------------------------\n");
} |
| Sponsor | ||
| ||
| |
![]() |
| | |
| building, matrices | |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| CVE-2008-2165 (Building Broadband Service Manager) | Heap | Advisories | 0 | 16-05-08 20:50 |