code to display output in desired format