Generate Pattern 2, 33, 222, 5555, 22222, 777777 using constraints

In reply to bachan21:

i think we can use hexadecimal format and shift operations to print this pattern

  1. take the input patterns like “3”,“5”,“7”,“9”,“11”,“13” …
  2. convert it to hex decimal numbers
    longint value = str.atohex();
  3. using below logic we can get format(num = 0 )
    for (int i = 1; i <= x; i++)
    num = (num << no_of_bits) + value;
    Note: number of bits to shift → no of bits needed to represent a input number in hexadecimal
    if ( ip_value < 16 ) no_of_bits = 4;
    else if ( (ip_value < 256) && ( ip_value >= 16)) no_of_bits = 8;

Hope it helps