Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I used this function to print an array of integers but does not work. In my particular case the function print casual number, I think. The result I would like to achieve is the vector is--->12345

THIS IS THE FUNCTION:

    void print_vector(int vector[], int n){
        int i=0;
        while(i<n){
            printf("%d", vector[i]);
            i++;
        }
    }

THE FULL CODE:

#include <stdio.h>
#include <stdlib.h>

int leggereinterointervallato(int inferiore,int superiore);
int leggereelencointeri(int elenco[],int n);
int contarepresenze7(int E[], int n);
void print_vector(int vector[], int n);

int main(void){
    int numero[10];

    leggereelencointeri(numero, 10);
    printf("
");
    print_vector(numero,10);
    printf("
");

    contarepresenze7(numero, 10);
    printf("il numero 7 e' presente %d volte
", contarepresenze7(numero, 10));

    system("pause");
    return 0;
}

int leggereinterointervallato(int inferiore,int superiore)
    {
        int numerointervallato;
        do{
        printf("inserire cifra del numero--->");
        scanf("%d",&numerointervallato);
            if((numerointervallato<inferiore) || (numerointervallato>superiore))
                printf("Il numero deve essere compreso tra %d e %d -->",inferiore,superiore);
        }while((numerointervallato<inferiore) || (numerointervallato>superiore));
        return numerointervallato;
    }


int leggereelencointeri(int elenco[],int n)
    {
        int p;
        p=1;
        while(p<=n)
        {
                elenco[p]=leggereinterointervallato(0,9);
                p=p+1;
        }
        return elenco[n];
    }

int contarepresenze7(int E[], int n)    {
    int i=0;
    int count=1;
    while(i<n){
        if(E[i]==7){
            count++;
        }
        i++;
    }
    return count;
}

void print_vector(int vector[], int n){
    int i=0;
    while(i<n){
        printf("%d", vector[i]);
        i++;
    }
}

The problem is that the function print_vector prints random numbers instead of printing vector numbers!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
165 views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...