Torna indietro   Hardware Upgrade Forum > Software > Programmazione

DS N°7 E-Tense: il SUV premium made in Melfi che punta su autonomia e comfort
DS N°7 E-Tense: il SUV premium made in Melfi che punta su autonomia e comfort
Fino a 740 km WLTP con la batteria da 97,2 kWh, sospensioni che leggono la strada con una telecamera e un abitacolo da salotto parigino. La nuova DS N°7 raccoglie l'eredità della DS 7 e la porta, per la prima volta, nel mondo 100% elettrico. Ecco come è fatta, cosa offre e quanto costa.
Recensione Samsung Galaxy Tab S12 Ultra: non chiamatelo tablet... è molto di più
Recensione Samsung Galaxy Tab S12 Ultra: non chiamatelo tablet... è molto di più
Abbiamo provato Samsung Galaxy Tab S12 Ultra nella versione 12 GB + 256 GB con tastiera, e il risultato è un tablet che in questa configurazione si comporta come un notebook con la fluidità tipica di Android. Spessore di 5,1 mm, display Dynamic AMOLED 2X da 14,6 pollici, MediaTek Dimensity 9500 e un software senza incertezze compongono un prodotto di vertice, con prezzi da 1.539 euro, frenato solo da un'autonomia nella parte bassa del confronto
Hyundai IONIQ 5 N, l'elettrica che finge di essere termica (e ci riesce da paura)
Hyundai IONIQ 5 N, l'elettrica che finge di essere termica (e ci riesce da paura)
Abbiamo provato per dieci giorni la Hyundai IONIQ 5 N, con 650 CV, 770 Nm e uno 0-100 km/h in 3,4 secondi. Il suo punto forte è N e-Shift, che simula un cambio a otto rapporti con suoni da motore termico e perfino un bang supersonico
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 13-06-2010, 12:30   #1
kwb
Senior Member
 
L'Avatar di kwb
 
Iscritto dal: Jul 2003
Città: Alessandria
Messaggi: 10167
[C]Array multidimensionali, comparazioni di matrici

Ciao a tutti, sto facendo questo programma che prese in input due matrix a e b, il programma in output restituisce se la matrice b è una sottomatrice di a...
Purtroppo, non sono ancora riuscito ad arrivare a questo punto, infatti ho problemi col caricamento dei dati nel vettore... E non capisco cosa non vada...
Infatti, i dati vengo caricati correttamente ( penso ) ma se metto una matrice 4 x 4 i dati inseriti vengono disposti su un'unica riga del terminale ( si noti che 4 è la grandezza massima di righe per la matrice, ho definito una costante apposta per questo ). Se vado invece a mettere una matrice 2 x 2 e scrivo, per esempio:
as
df

Questi mi vengono stampati correttamente... Scrivendo invece, nella 4 x 4:
qwer
tyui
asdf
ghjk

Mi viene stampato:
qwertyuiasdfghjk

Questo è il codice fin ora scritto:
Codice:
/*
 Write a C program that reads from keyboard 2 matrices of characters (of size at most 10x10), and then checks if the second matrix occurs
 as a sub-matrix in the first one.
 For example, let us consider the matrices
		A	B	C	k	F	m2: F G		m3: F G 
 m1:	D	E	F	G	A		K L			K i
		m	I	K	L	i
 
 m2 occurs in m1 as a sub-matrix while m3 does not. Be careful in not crossing the matrix boundaries.
*/

#include <stdio.h>
#define MAX 4 //Change to 10 when done

void get_matrix(char matrix[][MAX], int *n1, int *n2);
void empty_buffer(void);

int main (void) 
{
	int i=0, j=0; //Indexes for matrix 1
	int z=0, c=0; //Indexes for matrix 2
	char matrix[MAX][MAX];
	printf("This program read from keybord 2 matrices\n");
	printf("of character, and checks\n");
	printf("if the second matrix occurs\n");
	printf("as a submatrix in the first one.\n");
	for (i=0; i < MAX; i++)
		matrix[i][i]=0;
	i = 0;
	get_matrix(matrix, &i, &j);
    return 0;
}

void get_matrix(char matrix[][MAX], int *n1, int *n2)
{
	int i1, i2; //Indexes for the matrix, no matter which one
	
	printf("Insert the size ( rows ) of the matrix\n");
	scanf("%d", n1);
	while ( *n1 > MAX || *n1 <= 0 )
	{
		printf("You can enter only a number between 1 and %d\n", MAX);
		scanf("%d", n1);
	}
	printf("Your matrix will have %d rows\n", *n1);
	printf("Now enter the size ( columns ) of the matrix\n");
	scanf("%d", n2);
	while ( *n2 <= 0 )
	{
		printf("Your matrix must have at least 1 column\n");
		scanf("%d", n2);
	}
	printf("Your matrix will have %d columns\n", *n2);
	
	printf("Now enter your matrix, insert the characters for each row sequentially, without any space among them\n");
	printf("The program will automatically position the elements inserted\n");
	empty_buffer();
	for (i1=0; i1 < *n1; i1++)
	{
		for(i2=0; i2 <= *n2; i2++) // i2 has to be less or equal to *n2 because the loop stops only if i2 == *n2, is this the reason??
		{
			scanf("%c", &matrix[i1][i2]);
		}
	}
	printf("\n");
	for (i1=0; i1 < *n1; i1++)
	{
		for(i2=0; i2 <= *n2; i2++) // Same as written above
		{
				printf("%c", matrix[i1][i2]);
		}
	}
	
}

void empty_buffer(void)
{
	while(getchar() != '\n');
}
__________________
Dell XPS 13 (9350) :: i5-2500K - HD6870 - AsRock Z68 Pro3 - Corsair Vengeance 8GB (4x2) DDR3 :: Samsung Galaxy S4 GT-i9505
kwb è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


DS N°7 E-Tense: il SUV premium made in Melfi che punta su autonomia e comfort DS N°7 E-Tense: il SUV premium made in Melfi...
Recensione Samsung Galaxy Tab S12 Ultra: non chiamatelo tablet... è molto di più Recensione Samsung Galaxy Tab S12 Ultra: non chi...
Hyundai IONIQ 5 N, l'elettrica che finge di essere termica (e ci riesce da paura) Hyundai IONIQ 5 N, l'elettrica che finge di esse...
CES Unveiled Milan, l'IA diventa tecnologia fondativa e il commercio torna centrale CES Unveiled Milan, l'IA diventa tecnologia fond...
 Recensione OPPO Find X10 Pro Max: un top di gamma completo con tre fotocamere da 200MP Recensione OPPO Find X10 Pro Max: un top di gam...
Apple annuncia i nuovi MacBook Pro con s...
Warhorse Studios colpita da un grave att...
MX Master 4, arriva l'edizione speciale ...
Kali Linux 2026.3 porta la caccia alle r...
Oracle si affida a OpenAI: ChatGPT e Cod...
Kaspersky punta su IA e servizi gestiti ...
Già sfruttata la falla Brotli che...
Potrebbe essere stato scoperto un nuovo ...
Claude Code, il prompt per scovare telec...
Palit e GALAX smentiscono le voci sulla ...
Fujifilm annuncia la Instax Mini Evo 2, ...
Tailscale chiude le falle SSH verso root...
Il tuo Galaxy laggava nei giochi? Samsun...
Arrivano i nuovi Amazon Echo: prezzi da ...
Il nuovo pickup elettrico Ford può alime...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 04:01.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v