Professional Documents
Culture Documents
LAB 4 Answers
LAB 4 Answers
LAB 4 Answers
Etos 2020-2021
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int size;
int *matrix;
int i, sum = 0;
/* Desmeuw xwro */
matrix = (int *) malloc(size*sizeof(int));
if (matrix == NULL)
{
printf("Error in malloc\n");
return 1;
}
free(matrix);
return 0;
}
// Endeiktiki Lysi tis Askisis 4.2- Ak. Etos 2020-2021
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, n1 = 0, n2 = 0;
int *a1;
/* Print */
for (i = 0; i < n2; i++)
printf("%d ", a1[i]);
printf("\n");
return 0;
}
// Endeiktiki Lysi tis Askisis 4.3- Ak. Etos 2020-2021
#include <stdio.h>
#include <string.h> /* strlen(), strcpy() */
#include <stdlib.h> /* For malloc() */
return (new);
}
int main()
{
char arr[100], *copy;
#include <stdio.h>
#include <stdlib.h> /* For malloc(), free() */
if (argc < 2)
return 1;
n = atoi(argv[1]);
if (n < 1)
return 1;
p = pascal(n);
if (p == NULL)
return 1;
/* Print */
for (i = 0; i < n; i++)
{
for (j = 0; j <= i; j++)
printf("%2d ", p[i][j]);
printf("\n");
}
/* Free memory */
for (i = 0; i < n; i++)
free(p[i]); /* Free row i */
free(p); /* Free the array of pointers */
return 0;
}
int **pascal(int n)
{
int i, j;
int **array;
/* Calculate */
array[i][0] = 1;
for (j = 1; j < i; j++)
array[i][j] = array[i-1][j-1] + array[i-1][j];
array[i][i] = 1;
}
return (array);
}
// Endeiktiki Lysi tis Askisis 4.5- Ak. Etos 2020-2021
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
if (argc != 4)
exit(1); /* Don't do anything */
d = atoi(argv[2]); /* Distance */
if (d < 1 || d > 25)
{
printf("Distance should be > 0 and < 26\n");
exit(1);
}
if (strcmp(argv[1], "encrypt") == 0)
{
s = encrypt(argv[3], d);
printf("%s\n", s);
free(s);
}
else /* Assume it is "decrypt" */
{
decrypt(argv[3], d);
printf("%s\n", argv[3]);
}
return 0;
}