-1

I need to get an integer number with 99 digits. This is actually the question which I need to get an integer number with 99 digits to solve: https://quera.org/problemset/9774/

This is my code to solve that question but it should be able to get bigger number:

#include <stdlib.h>
int main(){
    long long int n;
    scanf("%lld",&n);
    long long int x=n;
    int i=1;
    while(x>=10){
        x=x/10;
        i++;
    }
    long long int ar[i];
    x=i-1;
    while(x>=0){

        ar[x]=n%10;
        n=n/10;
        x--;
    }
    x=0;
    int z=1;
    while(x<=i-1){

        printf("%d: ",ar[x]);
        while(z<=ar[x]){
            printf("%d",ar[x]);
            z++;
        }
        z=1;
        x++;
        printf("\n");

    }
   
    return 0;
     }
miken32
  • 42,008
  • 16
  • 111
  • 154
  • 3
    Even the `long long` data type is not large enough to be able to store a number with `99` digits. However, your assignment is not asking you to do that. It is merely asking you to count the number of occurrances of the individual digits. For this, it is best to read and process the input as a string. – Andreas Wenzel Apr 01 '23 at 13:44
  • Please include the problem statement, in english, directly in the question, – dbush Apr 01 '23 at 13:44
  • Thanks every one. It solved.I used string and strlen function instead of integer variable. – Pedram Arianmanesh Apr 02 '23 at 19:45

2 Answers2

3

There is no inter type which can hold 99 digits integer number and thus you cant scanf it.

The largest number gcc (but it is not standard C) can handle as integer is 128bit long. But the max number you can store there is 170141183460469231731687303715884105727, which is far too short.

So the answer is: You can't use scanf to scan 99 digits long integer number

The only way is read as a string and then use libraries like GMP

0___________
  • 60,014
  • 4
  • 34
  • 74
0

Thanks every one for help.It solved:) I used string and strlen function instead of integer. This new code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
    char n[99];
    scanf("%s",&n);
    int i =strlen(n);

   int x=0;
    int z=1;
    while(x<=i-1){
        int a=n[x]-48;
        printf("%d: ",a);
        while(z<=a){
            printf("%d",a);
            z++;
        }
        z=1;
        x++;
        printf("\n");

    }

    return 0;
     }