-
.
#include <stdio.h>
#define MAX 8
#define MIN 1
typedef struct{
int matrice[MAX][MAX];
int maxrighe;
int maxcolonne;
}scacchiera;
int leggereRighe(scacchiera matrice){
int righe;
righe = matrice.maxrighe;
return righe;
}
int leggereColonne(scacchiera matrice){
int colonne;
colonne = matrice.maxcolonne;
return colonne;
}
int leggereValore(scacchiera matrice, int riga, int colonna){
int valore;
valore = matrice.matrice[riga][colonna];
return valore;
}
scacchiera scrivereRighe(scacchiera matrice, int riga){
matrice.maxrighe = riga;
return matrice;
}
scacchiera scrivereColonne(scacchiera matrice, int colonna){
matrice.maxcolonne = colonna;
return matrice;
}
scacchiera scrivereValore(scacchiera matrice, int riga, int colonna, int valore){
matrice.matrice[riga-1][colonna-1] = valore;
return matrice;
} -
.
SCACCHIERA – tipo record
VALORI – matrice dedicata alla scacchiera – int
RIGHE – variabile contenente il numero di righe della scacchiera – int
COLONNE – variabile contenete il numero di colonne della scacchiera – int
int leggereRighe(scacchiera matrice){
int righe;
righe = matrice.maxrighe;
return righe;
}
int leggereColonne(scacchiera matrice){
int colonne;
colonne = matrice.maxcolonne;
return colonne;
}
int leggereValore(scacchiera matrice, int riga, int colonna){
int valore;
valore = matrice.matrice[riga][colonna];
return valore;
}
scacchiera scrivereRighe(scacchiera matrice, int riga){
matrice.maxrighe = riga;
return matrice;
}
scacchiera scrivereColonne(scacchiera matrice, int colonna){
matrice.maxcolonne = colonna;
return matrice;
}
scacchiera scrivereValore(scacchiera matrice, int riga, int colonna, int valore){
matrice.matrice[riga-1][colonna-1] = valore;
return matrice;
}
typedef struct{
int matrice[MAX][MAX];
int maxrighe;
int maxcolonne;
}scacchiera;
Raga una domanda: perché in qualsiasi caso mi restituisce 1?
int vittoriaRegina(scacchiera s, int rRE, int cRE, int rRA, int cRA){
int mangia;
rRE = s.riga;
rRA = s.riga;
cRE = s.colonna;
cRA = s.colonna;
if(rRE == rRA){
mangia = 1;
}
else if(cRE == cRA){
mangia = 1;
}
else if(abs(cRE - cRA) == abs(rRE - rRA)){
mangia = 1;
}
else{
mangia = 0;
}
return mangia;
}
Raga una domanda: perché in qualsiasi caso mi restituisce 1?
int vittoriaRegina(scacchiera s, int rRE, int cRE, int rRA, int cRA){
int mangia;
rRE = s.riga;
rRA = s.riga;
cRE = s.colonna;
cRA = s.colonna;
if(rRE == rRA){
mangia = 1;
}
else if(cRE == cRA){
mangia = 1;
}
else if(abs(cRE - cRA) == abs(rRE - rRA)){
mangia = 1;
}
else{
mangia = 0;
}
return mangia;
} -
.
Esercitazione del 16 dicembre 2021
Su una scacchiera 8x8 sono posizionati due pezzi: il Re bianco e la Regina nera. Si scriva una funzione the riceve in input le posizioni del Re e della Regina e determini se la Regina 6 in posizione tale da poter mangiare il Re. Le posizioni dei due pezzi sono identificate mediante la riga e la colonna su cui si trovano, espresse come numeri interi tra 1 e 8.
II tipo di dato scacchiera deve essere rappresentato come un record contenente un vettore statico di interi a 2 dimensioni e due interi rappresentanti le dimensioni. Realizzare le funzioni accesso al tipo di dato scacchiera.
N.B. Realizzare gli algoritmi di tutte le funzioni individuate e il codice in linguaggio C e consegnare entro le 18.00
#include<stdio.h>
#include "safeio.h"
typedef struct
{
int x;
int y;
}position;
int check_upper_left_diagonal(position king_position,position queen_position)
{
int is_king_in_danger = 0;
for(int x = king_position.x; x <= 8 && is_king_in_danger == 0;x++)
{
is_king_in_danger = x == queen_position.x && x == queen_position.y ;
}
if(is_king_in_danger == 0)
{
for(int x = king_position.x; x >= 0 && is_king_in_danger == 0;x--)
{
is_king_in_danger = x == queen_position.x && x == queen_position.y ;
}
}
return is_king_in_danger;
}
int main()
{
printf("Posizione X Re:\t");
position king_position;
king_position.x = get_int();
printf("Posizione Y Re:\t");
king_position.y = get_int();
printf("Posizione X Regina:\t");
position queen_position;
queen_position.x = get_int();
printf("Posizione Y Regina:\t");
queen_position.y = get_int();
printf("Re in pericolo: %d\n",is_king_in_danger);
} -
.
#include <stdio.h>
#include <stdib.h>
#define MAX 30
typedef struct {
int valori[MAX][MAX];
int righe;
int colonne;
}tabella;
//prototipi
int LeggereRighe(tabella t);
int LeggereColonne(tabella t);
int LeggereValori (tabella t, int r, int c);
int main(void) {
tabella t1;
t1.righe=LeggereRighe(tabella t);
t1.colonne=LeggereColonne(t1);
t1.valori=LeggereValori(t1, t1.righe, t1.colonne);
return EXIT_SUCCESS;
int LeggereRighe(tabella t){ -
.
t1.righe=LeggereRighe(t1);
t1.colonne=LeggereColonne(t1);
t1.valori=[][]=LeggereValori(t1, t1.righe, t1.colonne);
t1.lines = Read Lines (t1); t1.columns = Read Columns (t1); t1.values = [] [] = ReadValues (t1, t1.lines, t1.columns);
t1.linhas = ler linhas(t1); t1.colunas = Ler colunas (t1); t1.values = [] [] = ReadValues (t1, t1.linhas, t1.colunas); -
.
1/ 18 tl.righe=LeggereRighe(t1); 19 tl.colonne=LeggereColonne(t1); gi20 talariilUNWACAWSZWVai, 21 -
.
Olha a pergunta é abstrata, mas vou te dar uma resposta agnóstica da linguagem.
Eu primeiro criaria um array pra guardar esses dados que seriam lidos, escritos e etc)
Depois criaria uma função pra cada operação: ler(), escrever valor(), etc.
Por último, eu criaria uma última função que vai ler todos os valores desse array e mostraria isso no console, formatado igual ele pede, em forma de tabela.
Sua responsabilidade transformar isso em código.
Ascolta, la domanda è astratta, ma ti darò una risposta indipendente dalla lingua.
Prima creerei un array per memorizzare questi dati che verrebbero letti, scritti, ecc.)
Quindi creerei una funzione per ogni operazione: read(), write value(), ecc.
Infine, creerei un'ultima funzione che leggerà tutti i valori da questo array e li mostrerà sulla console, formattata come chiede, in forma di tabella.
È tua responsabilità codificare questo. -
.
- create the pseudocode and code of the 6 access functions (read / write value, read / write row, read / write column);
- create pseudocode and code of the functions for inserting all the values and printing all the values of a table -
.
Creati una struct con un puntatore e due unsigned, in cui uno tiene traccia delle righe e uno delle colonne
Scrivi questo nell'header
#include <stddef.h>
#include <stdint.h>
typedef struct t_Table* Table;
Table table_create(size_t type_size);
void table_destroy(Table);
int table_get_element(const Table, size_t row, size_t col, void* pElement);
int table_set_element(Table, size_t row, size_col, const void* pElement);
size_t table_rows(const Table);
size_t table_cols(const Table);
size_t table_size(const Table);
int table_get_row(const Table, size_t row, void*);
int table_set_row(Table, size_t row, const void*);
int table_get_col(const Table, size_t col, void*);
int table_set_col(Table, size_t col, const void*);
int table_insert_row(Table, size_t where, const void*);
int table_insert_col(Table, size_t where, const void*);
int table_push_front_row(Table, const void*);
int table_push_front_col(Table, const void*);
int table_push_back_row(Table, const void*);
int table_push_back_col(Table, const void*);
int table_remove_row(Table, size_t which, void*);
int table_remove_col(Table, size_t which, void*);
int table_pop_front_row(Table, void*);
int table_pop_front_col(Table, void*);
int table_pop_back_row(Table, void*);
int table_pop_back_col(Table, void*);
void* table_data(Table); -
.
https://www.google.com/search?q=leggere...mobile&ie=UTF-8
leggere/scrivere valore, leggere/scrivere riga, leggere/scrivere colonna
ANO PARA 18 DE DEZEMBRO (CASO ESTÁTICO)
- criar o pseudocódigo e o código das 6 funções de acesso;
- criar pseudocódigo e código das funções para inserir todos os valores e imprimir todos os valores de uma tabela
Exemplos:
tabela interna [5] [7];
tabela [2] [3] = 25;
#define LINHAS 5
#define COLUNAS 7
tabela interna [ROWS] [COLUMNS]
tabela [2] [3] = 5
número real
número negro
# define LINHAS 50
# define COLUNAS 70
tabela interna [LINHAS] [COLUNAS];
int table1 [ROWS1] [COLUMNS1];
número real
número negro
int * table;
tabela = (int *) malloc (sizeof (int) * número verdadeiro * número da coluna);
* (mesa + 2 + 3)
// TRUE array dinâmico bidimensional
Tabela Int **;
tabela = (int **) malloc (sizeof (int *) * número da coluna)
i = 0
while (i <número da coluna) // chave
* (Tabela + i) = (int) malloc (sizeof (int) * número da linha);
i = i + 1;
// colchete
* (* (tabela + 3) +2) = 25; i = 0;
enquanto (i <número de linho)
int * * table;
* (* (tabela + 3) +2) = 25;
* (* (mesa + 3) +1) = * (* (mesa + 2) +3);
* (mesa + 2 + 3) =
i = 0;
while (i <t1.lines) {
* (t1.valores + i) = (int)
malloc (sizeof (int) * t1.column);
i = i + 1;
typedef struct {
valores int [MAX] [MAX];
linhas internas;
colunas int;
} tabela;
Int ReadValue (tabela t, int r, int c)
{
return t.values [r] [c];
}
Linhas de gravação da tabela (tabela t, linhas internas)
{t1 linhas = linhas;
return t;
}
Linhas de leitura interna (tabela t)
{
return t.lines;
}
Tabela WriteValue (tabela t, int r, int c, valor int)
{
r.values [r] [c] = valor;
Return t;
}
ENTRADA
Tabula a partir da qual ler o número de linhas - tabela
SAÍDA
Linhas - número de linhas t - inteiro> 0
ALGORITMO
Linhas = campo de linhas de t
- criar o pseudocódigo e o código das 6 funções de acesso (ler/escrever valor, ler /escrever linha, ler/escrever coluna);
- criar pseudocódigo e código das funções para inserir todos os valores e imprimir todos os valores de uma tabela
- Criar o pseudocódigo e o código das 6 funções de acesso (ler/escrever valor, ler /escrever linha, ler/escrever coluna);
- Criar pseudocódigo e código das funções para inserir todos os valores e imprimir todos os valores de uma tabela
Na linguagem C, como faço para resolver este exercício?
ESERCIZIO PER IL 18 DICEMBRE (CASO STATICO)
- realizzare lo pseudocodice e codice delle 6 funzioni di accesso (leggere/scrivere valore, leggere/scrivere riga, leggere/scrivere colonna);
- realizzare pseudocodice e codice delle funzioni di inserimento di tutti i valori e di stampa di tutti i valori di una tabella -
.
YEAR FOR 18 DECEMBER (STATIC CASE)
- create the pseudocode and code of the 6 access functions;
- create pseudocode and code of the functions for inserting all the values and printing all the values of a table
Examples:
int table [5] [7];
table [2] [3] = 25;
#define LINES 5
#define COLUMNS 7
int table [ROWS] [COLUMNS]
table [2] [3] = 5
real number
blacknumber
#define LINES 50
#define COLUMNS 70
int table [ROWS] [COLUMNS];
int table1 [ROWS1] [COLUMNS1];
real number
blacknumber
int * table;
table = (int *) malloc (sizeof (int) * true number * column number);
* (table + 2 + 3)
// TRUE two dimensional dynamic array
Int ** table;
table = (int **) malloc (sizeof (int *) * columnnumber)
i = 0
while (i <column number) // brace
* (Table + i) = (int) malloc (sizeof (int) * rownumber);
i = i + 1;
// bracket
* (* (table + 3) +2) = 25; i = 0;
while (i <linenumber)
int * * table;
* (* (table + 3) +2) = 25;
* (* (table + 3) +1) = * (* (table + 2) +3);
* (table + 2 + 3) =
i = 0;
while (i <t1.lines) {
* (t1.values + i) = (int)
malloc (sizeof (int) * t1.column);
i = i + 1;
typedef struct {
int values [MAX] [MAX];
int lines;
int columns;
}table;
Int ReadValue (table t, int r, int c)
{
return t.values [r] [c];
}
Table Write Lines (table t, int lines)
{t1 lines = lines;
return t;
}
Int Read Lines (table t)
{
return t.lines;
}
Table WriteValue (table t, int r, int c, int value)
{
r.values [r] [c] = value;
Return t;
}
INPUT
Tabula from which to read the number of rows - table
OUTPUT
Lines - number of lines t - integer> 0
ALGORITHM
Rows = rows field of t -
.
ESERCIZIO PER IL 18 DICEMBRE (CASO STATICO)
- realizzare lo pseudocodice e codice delle 6 funzioni di accesso;
- realizzare pseudocodice e codice delle funzioni di inserimento di tutti i valori e di stampa di tutti i valori di una tabella
Esempi:
int tabella [5] [7];
tabella [2] [3] = 25;
#define RIGHE 5
#define COLONNE 7
int tabella [RIGHE] [COLONNE]
tabella [2] [3] = 5
numerorighereale
numerocolonnereale
#define RIGHE 50
#define COLONNE 70
int tabella [RIGHE] [COLONNE];
int tabella1 [RIGHE1] [COLONNE1];
numerorighereale
numerocolonnereale
int * tabella;
tabella=(int *) malloc (sizeof(int)*numerorighereale*numerocolonne);
*(tabella+2+3)
//array dinamico a due dimensioni VERE
Int **tabella;
tabella=(int **) malloc (sizeof(int *)*numerocolonne)
i=0
while (i<numerocolonne) //parentesi graffa
*(Tabella+i)=(int) malloc (sizeof(int)*numerorighe);
i=i+1;
//parentesigraffa
*(*(tabella+3)+2) = 25; i=0;
while (i<numerorighe)
int * * tabella;
*(*(tabella+3)+2)=25;
*(*(tabella+3)+1)=*(*(tabella+2)+3);
*(tabella+2+3)=
i=0;
while (i<t1.righe){
*(t1.valori+i)=(int)
malloc(sizeof(int)*t1.colonna);
i=i+1;
typedef struct{
int valori [MAX] [MAX];
int righe;
int colonne;
}tabella;
Int LeggereValore (tabella t, int r, int c)
{
return t.valori [r] [c];
}
TabellaScrivereRighe (tabella t, int righe)
{t1 righe = righe;
return t;
}
Int LeggereRighe (tabella t)
{
return t.righe;
}
Tabella ScrivereValore (tabella t, int r, int c, int valore)
{
r.valori [r] [c] = valore;
Return t;
}
INPUT
Tabula di cui leggere il numero di righe - tabella
OUTPUT
Righe - numero di righe t - intero > 0
ALGORITMO
Righe = campo righe di t -
.
ESERCIZIO PER IL 18 DICEMBRE (CASO STATICO)
- realizzare lo pseudocodice e codice delle 6 funzioni di accesso;
- realizzare pseudocodice e codice delle funzioni di inserimento di tutti i valori e di stampa di tutti i valori di una tabella -
.
typedef struct {
int * valori;
int righe;
int colonne;
} tabella
#define RIGHE 5
#define COLONNE 7
int tabella [RIGHE][COLONNE];
tabella[2][3,],=
#define RIGHE 50
#define COLONNE 70
int tabella [RIGHE] [COLONNE];
int tabella1 [RIGHE1] [COLONNE1]; -
.
#include <stdio.h>
#include <stdlib.h>
#define DIM1 10
#define DIM2 20
//prototipi
int LeggereCardinalit(int inf, int sup);
void LeggereArray(char stringa[], int dim);
int main(void) {
char str1[DIM1];
char str2[DIM2];
int n1;
int n2;
int lung1;
int lung2;
str1[DIM1+1]='\0';
str2[DIM2+1]='\0';
n1=LeggereCardinalit(0, 10);
LeggereArray(str1, n1);
n2=LeggereCardinalit(0, 10);
LeggereArray(str2, n2);
lung1=0;
lung2=0;
lung1 = strlen(str1);
lung2 = strlen(str2);
printf("%d", lung1);
printf("%d", lung2);
system("pause");
return EXIT_SUCCESS;
}
int LeggereCardinalit(int inf, int sup){
int dim; //numero di elementi di un vettore, intero, >0
do {
printf("Inserire il numero di elementi dell'elenco >0: ");
scanf("%d", &dim);
if(dim<=inf){
printf("ERRORE. IL NUMERO DEGLI ELEMENTI DEVE ESSERE MAGGIORE DI 0!");
}
}while((dim<=inf) || (dim>=sup));
return dim;
}
void LeggereArray(char stringa[], int dim){
int i; //contatore degli elementi dell’array letti, intero, >0, <=dim
i=0;
while(i<dim){
printf("inserire elemento dell' array:");
scanf("%c", &stringa[i]);
i=i+1;
}
return;
}