Last active
August 29, 2015 14:09
-
-
Save Evshved/becb5ae8c977fa9828a2 to your computer and use it in GitHub Desktop.
Lab#6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <vcl.h> // Visual Component Library | |
| #include <stdio.h> // standard input/output header | |
| #include <conio.h> //console input-output | |
| #include <math.h> //mathematics | |
| #include <stdlib.h> //standard library | |
| #include <alloc.h> //work with dynamic memory | |
| #pragma hdrstop // | |
| #pragma argsused // | |
| int main(int argc, char* argv[]) //1 сделать зацикливание x 2 рандом или ввод с клавы 3 x изучить маллок и каллок | |
| { | |
| int i,k,m,n,j,max,f,sign; | |
| int **a; | |
| do { | |
| clrscr(); | |
| printf("Quest :''Max element that lie among the elements below the secondary diagonal.''\n"); | |
| do { | |
| printf("Please type '1' for random array, other digits for your array.\n"); | |
| fflush(stdin); | |
| }while(scanf("%d",&sign) !=1); | |
| do { | |
| do { | |
| fflush(stdin); | |
| printf("Enter the number of strings and columns\n"); | |
| }while(scanf("%d", &n) !=1); | |
| }while(n<2); | |
| m=n; | |
| // | |
| //coreleft() | |
| //create dynamic massive n*m | |
| a=(int**) calloc(n,sizeof (int*)); // a = new int*[n]; | |
| //разобраться с утечкой памяти | |
| //int **a= malloc(n *sizeof(int)); | |
| if (!a){ //a==NULL | |
| perror("calloc"); | |
| continue; | |
| } | |
| //разобраться с маллоком | |
| for(i=0; i<n; i++){ | |
| a[i] = (int*) calloc(m,sizeof (int)); // a[i] = new int[m]; | |
| //a[i]=(int*) malloc(m); | |
| } | |
| if (sign==1) { //randomize massive | |
| randomize(); // random number generator | |
| for(i=0; i<n; i++){ | |
| for(k=0; k<m; k++){ | |
| a[i][k]=random(10); | |
| } | |
| } | |
| } | |
| else { | |
| for (i=0;i<n;i++){ | |
| for(k=0;k<m;k++){ | |
| printf("a[%d][%d] ",i,k); | |
| scanf("%d",&a[i][k]); | |
| } | |
| } | |
| } | |
| //output on screen all massive | |
| for(i=0; i<n; i++){ | |
| for(k=0; k<m; k++){ | |
| printf("%d ",(a[i][k])); | |
| } | |
| printf("\n\n"); | |
| } | |
| /*output on screen all after secondary diagonal |0 0 0| | |
| |0 0 1| | |
| |0 1 1| | |
| добиться красивого вывода | |
| */ | |
| m=n; | |
| printf("\n"); | |
| for(i=0,j=n; i<n; i++){ | |
| j--; | |
| for (k=0;k<m;k++) { | |
| if (k<=j) { | |
| printf("x ",(a[i][k])); | |
| } | |
| else { | |
| printf("%d ",(a[i][k])); | |
| } | |
| } | |
| printf("\n\n"); | |
| } | |
| //find max | |
| max=a[n-1][n-1]; | |
| for(i=0,j=n; i<n; i++){ | |
| j--; | |
| for(k=n-1; k>j; k--){ | |
| if (max<a[i][k]){ | |
| max=a[i][k]; | |
| } | |
| } | |
| } | |
| printf("\nMax=%d",max); | |
| for(i=0; i<n; i++){ //clearing memory | |
| free (a[i]); //delete[]a[i]; | |
| } | |
| free(a); //delete[]a; | |
| puts("\nExit - 1, Restart - any key"); | |
| } while ( getch() != '1'); | |
| } | |
| //--------------------------------------------------------------------------- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment