Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string.h>
- #include <stdlib.h>
- #include <math.h>
- using namespace std;
- #define MATRIX_HEIGHT 6
- #define MATRIX_WIDTH 5
- int Matrix[MATRIX_HEIGHT][MATRIX_WIDTH];
- void prob_1()
- {
- char text[9999];
- int row[1001];
- int i=0;
- FILE * file;
- file = fopen("prob_1_text.txt","r");
- while(fgets(text,5,file)!=NULL)
- {
- row[i]=atoi(text);
- i++;
- }
- int n=i;
- for(i=0;i<n;i++)
- for(int j=i+1;j<=n;j++)
- if(row[i]>row[j])
- {
- int aux=row[i];
- row[i]=row[j];
- row[j]=aux;
- }
- for(i=1;i<=n;i++)
- cout<<row[i]<<" ";
- }
- double dist_pct(int ax,int ay, int cx, int cy)
- {
- double dist;
- dist = ceil(sqrt(((ax-cx)*(ax-cx))+((ay-cy)*(ay-cy))));
- return dist;
- }
- void prob_2(int* ptr,int cx,int cy,int ray)
- {
- int i;
- int j;
- int matrix[11][11] = { 0 };
- for(i=0;i<11;i++)
- for(j=0;j<11;j++)
- if(dist_pct(j,i,cx,cy)==ray)
- matrix[i][j]=1;
- for(i=0;i<11;i++)
- {
- for(j=0;j<11;j++)
- cout<<matrix[i][j]<<" ";
- cout<<endl;
- }
- }
- int main()
- {
- cout<<"Problema 1:"<<endl;
- prob_1();
- cout<<endl<<endl;
- cout<<"Problema 2:"<<endl;
- int i;
- int j;
- int matrix[11][11] = { 0 };
- prob_2(&matrix[0][0],2,2,2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement