Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    124

    [C] 2 semplici esercizi

    chi mi aiuta a risolvere questo semplice esercizio in C?

    codificare un programma che calcoli la seguente espressione: y=xa+b , dove x è uguale a 5, a è uguale a 18 e b è uguale a 7; x,a e b devono essere dichiarate come variabili intere. Si infine il valore finale:

    y=97

    trasformare il programma dell'esercizio precedente in modo che il valore di x venga richiesto all'utente in fase di esecuzione

    naturalmente se possibile vorrei capire i vari passaggi della risoluzione

    grazie

  2. #2
    Utente di HTML.it L'avatar di JamesD
    Registrato dal
    Oct 2001
    Messaggi
    415
    codice:
    void main{
    	int a, b, x, y;
    	a=18;
    	b=7;
    	x=5;
    	y=x*a+b;
    	printf("Il valore finale e': %d", y);
    }
    
    void main{
    	int a, b, x, y;
    	a=18;
    	b=7;
    	printf("Inserisci il valore della x: ");
    	scanf("%d", &x);
    	y=x*a+b;
    	printf("\nIl valore finale e': %d", y);
    }
    Si spiega da solo no?

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    124
    sì, credevo fosse più complicato

    grazie e ciao

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    124
    mi aiuteresti anche a compilarlo? gcc mi da questi errori:

    codice:
    esercizio.c:1: error: syntax error before '{' token
    esercizio.c:3: warning: data definition has no type or storage class
    esercizio.c:4: warning: data definition has no type or storage class
    esercizio.c:5: warning: data definition has no type or storage class
    esercizio.c:6: error: initializer element is not constant
    esercizio.c:6: warning: data definition has no type or storage class
    esercizio.c:7: error: parse error before string constant
    esercizio.c:7: warning: conflicting types for built-in function `printf'
    esercizio.c:7: warning: data definition has no type or storage class
    esercizio.c:10: error: syntax error before '{' token
    esercizio.c:12: error: redefinition of `a'
    esercizio.c:3: error: `a' previously defined here
    esercizio.c:12: warning: data definition has no type or storage class
    esercizio.c:13: error: redefinition of `b'
    esercizio.c:4: error: `b' previously defined here
    esercizio.c:13: warning: data definition has no type or storage class
    esercizio.c:14: error: parse error before string constant
    esercizio.c:14: warning: data definition has no type or storage class
    esercizio.c:15: error: parse error before string constant
    esercizio.c:15: warning: conflicting types for built-in function `scanf'
    esercizio.c:15: warning: data definition has no type or storage class
    esercizio.c:16: error: redefinition of `y'
    esercizio.c:6: error: `y' previously defined here
    esercizio.c:16: error: initializer element is not constant
    esercizio.c:16: warning: data definition has no type or storage class
    esercizio.c:17: error: parse error before string constant
    esercizio.c:17: warning: data definition has no type or storage class
    scusa ma sono proprio niubbo

  5. #5
    Utente di HTML.it L'avatar di JamesD
    Registrato dal
    Oct 2001
    Messaggi
    415
    sorry!!

    void main()...

    mi sono dimenticato le parentesi!!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.