Cognizant Interview Question

Write a logic to print patterns