'C problem not showing output with printf using arrays and functions
i wrote this code that asks to the user to input how many numbers wants to input, then asks for the numbers and from this creates an array then:
- call the function VerificaSequenza
- checks that the sum of the first two is equal to the third one
- if yes does this again with the second and the third equal to the forth and so on
- returns back 1 if is true false if not
the Question is: why i can't even see on the screen the printf messages? it just finishes immediately without asking for numbers and without printing
#include<stdio.h>
int VerificaSequenza(int lunghezza, int sequenza[])
{
int ContoSomma = lunghezza - 1;
int casella1 = 0;
int casella2 = 1;
int risultato = 2;
int controllo;
int i;
int messaggio;
for(i=0; i<ContoSomma; i++)
controllo = sequenza[casella1] + sequenza[casella2];
++casella1;
++casella2;
if (controllo == sequenza[risultato])
{
messaggio = 1;
++risultato;
}
else
{
messaggio = 0;
return messaggio;
}
}
int main()
{
int lunghezza;
int sequenza[lunghezza];
printf("Da quanti numeri è composta la sequenza?");
scanf("%d", &lunghezza);
printf("scrivi la sequenza");
for(int i=0; i<lunghezza; i++)
scanf("%d", &sequenza[i]);
int messaggio = VerificaSequenza(lunghezza, sequenza);
printf("%d", messaggio);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
