Code giving wrong output

on giving input 6 the pattern is incomplete