Professional Documents
Culture Documents
LAB 3 Answers
LAB 3 Answers
Etos 2020-2021
/* Simple calculator */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
/* Prosthetw ta orismata */
for (i=2; i<argc; i++)
result += atoi(argv[i]);
}
else if (strcmp(argv[1], "-") == 0)
{
result = atoi(argv[2]);
/* Pollaplasiazw ta orismata */
for (i=2; i<argc; i++)
result *= atoi(argv[i]);
}
else if (strcmp(argv[1], "/") == 0)
{
result = atoi(argv[2]);
#include <stdio.h>
#define N 10
δείκτης σε δείκτη ακεραίων
void search(int array[], int size, int num, int **res); /* prototype
*/
int main(void)
{
/* Arxikopoiw tous pinakes */
int A[N] = {0, 4, 8, 2, -2, 100, 45, -12, 45, 31};
int *res;
που είναι μεταβλητή δείκτη σε ακέραιο.
/* To res prepei na perastei me anafora, ara pernaw ti d/nsi
tou */
search(A, N, 100, &res);
if (res != NULL)
{
printf("Number=%d, position(0-%d)=%ld\n", *res, N-1,
res-A);
}
else
{
printf("Number not found!\n");
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char input[100];
int i;
return 0;
}
#include <stdio.h>
#define DIGITS 16
int check_card_number(char *str);
if (argc < 2)
printf("please re-run and supply 16-digit credit card
numbers\n");
else
for (i = 1; i < argc; i++)
{
res = check_card_number(argv[i]);
printf("Card %s is %s\n", argv[i], (res == 1)
? "valid" : "invalid");
}
return 0;
}
/* Small dictionary */
#include <stdio.h>
#include <string.h>
#define N 8
#define M 32
int main(void)
{
/* Initialize the dictionary */
char *dic[N] = {
"Hello",
"World",
"This",
"is",
"a",
"very",
"small",
"dictionary"
};
char user_input[M];
int i;
int found;
while (1)
{
/* Prompt for input */
printf("\n\nType a word or \"fin\" to exit program:
");
/* If we used fgets(), we should remove the trailing
\n */
scanf("%s", user_input);
if (found)
printf("Word: \"%s\" exists in dictionary\n",
user_input);
else
printf("Word: \"%s\" DOES NOT exist in
dictionary\n", user_input);
}
return 0;
}
// Endeiktiki Lysi tis Askisis 3.6 - Ak. Etos 2020-2021
/* Nameday calendar */
#include <stdio.h>
#include <string.h>
#define N 5
char *dates[N] = {
"12/12",
"6/12",
"30/11",
"12/6",
"13/5"
};
char *names[N] = {
"Spiros, Spiridoula",
"Nikolaos, Nikoletta, Niki",
"Andreas, Andriana, Andromaxi, Maxi",
"Onoufrios",
"Glykeria"
};
return 0;
}