lundi 5 octobre 2020

Add Variable If in for

I want to display the variable hm more than 0, but it always displays 0. How can I fix this?

#include <stdio.h>
#include <stdlib.h>
int main(void) {
    long long result = 1;
    int n;
    int i;
    char str[13500];
    int hm=0;  
    scanf("%d", &n);    
    for(i=0;i<n;i++) {
        result *= 9;
        sprintf(str, "%lld", result);
        printf("%c ",str[0]);
        if (str[0] == 9) {
            hm=hm+1;
        }      
    }
    printf("%d", hm); 
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire