Si scriva una funzione ricorsiva che data una lista di caratteri L calcoli il numero di cifre contenute nella lista.
int conta_cifre(L_PTR L)
a->3->f->d->j->4->NULL la funzione restituirā 2
Codice HTML:
#include <stdio.h>
struct nodo{
int data;
struct nodo *next}
int main(){
typedef struct nodo NODO;
typedef struct nodo *NEXT;
int conta_cifre(NODO L1){
if(L1->data!=NULL){
if((L1->data>='0')&&(L1->data<=9)){
return (L1->data-'0') + conto_cifre(L1->NEXT);}
else return conto_cifre(L1->NEXT);}
else return 0;}
La funzione dovrebbe essere corretta, ma non so se ho dichiarato bene la struttura e ho usato bene i nomi della lista.