Problem Statement :
Identify the logic behind the series 6 28 66 120 190 276….. The numbers in the series should be used to create a Pyramid. The base of the Pyramid will be the widest and will start converging towards the top where there will only be one element. Each successive layer will have one number less than that on the layer below it. The width of the Pyramid is specified by an input parameter N. In other words there will be N numbers on the bottom layer of the pyramid.
The Pyramid construction rules are as follows
- First number in the series should be at the top of the Pyramid
- Last N number of the series should be on the bottommost layer of the Pyramid, with Nth number being the right-most number of this layer.
- Numbers less than 5-digits must be padded with zeroes to maintain the sanctity of a Pyramid when printed. Have a look at the examples below to get a pictorial understanding of what this rule actually means.
Example
If input is 2, output will be
00006
00028 00066
If input is 3, output will be
00006
00028 00066
00120 00190 00276
Input Format:
First line of input will contain number N that corresponds to the width of the bottom-most layer of the Pyramid
Output Format:
The Pyramid constructed out of numbers in the series as per stated construction rules
Constraints:
0<N<=14
Sample Input 1 :
2
Sample Output 1 :
00006
00028 00066
Solution:
C
//www.codewindow.in
//start
#include<stdio.h>
int main()
{
int x=6,y=22,n,i,j,k=0;
scanf("%d",&n);
if(n>0 && n<=14)
{
for(i=1;i<=n;i++)
{
for(j=i;j<n;j++)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("%05d ",x);
x=x+y;
y=y+16;
}
printf("\n");
}
}
return 0;
}
//end
JAVA
//www.codewindow.in
//start
import java.util.*;
public class Main
{
public static void main(String[] args)
{
int x=6,y=22,n,i,j,k=0;
Scanner ip=new Scanner(System.in);
n=ip.nextInt();
if(n>0 && n<=14)
{
for(i=1;i<=n;i++)
{
for(j=i;j<n;j++)
{
System.out.printf(" ");
}
for(k=1;k<=i;k++)
{
System.out.printf("%05d ",x);
x=x+y;
y=y+16;
}
System.out.printf("\n");
}
}
}
}
//end
Python
#www.codewindow.in
#please follow the indentation as its a must in python programing
n=int(input())
x=6
y=22
if(n>0 and n<=14):
for i in range(1,n+1):
for j in range(i,n):
print(" ",end="")
for k in range(1,i+1):
print("%05d"%x,end=" ")
x=x+y
y=y+16
print()
#end
Follow Us
Also checkout
- Questions on Ages Explained – Top 9 Promising Aptitude Questions on Ages – codewindow.in
- Mindtree Off-Campusing | Junior Software engineer for cyber security | codewindow.in
- Kantar Off-Campusing | Software Engineer | codewindow.in
- HSBC Off-Campusing | Trainee Software Engineer/Group Data Technology | codewindow.in
- Sprinto Off-Campusing | Product Intern | codewindow.in
- Wipro Fresher Off-Campusing | Project Engineer | codewindow.in
- GlobalLogic Off-Campusing | Associate Software Engineer | codewindow.in
- GAVS Off Campus Hiring Drive – Trainee Software Engineer – Codewindow.in
- 3DS Off-Campusing | QA Automation Developer for Information Systems | codewindow.in
- Deloitte Off-Campusing | Associate Analyst – HR Analytics | codewindow.in
- Siemens Off-Campusing | Software Developer | codewindow.in
- Infosys Off Campus Recruitment Drive | Codewindow.in
- IBM Off Campus Drive 2022 – Associate Systems Engineer – codewindow.in
- Hexaware Off-campusing – Graduate Trainee – codewindow.in
- Accenture Off-Campusing – System and Application Services Associate – codewindow.in
- TCS Off Campus Hiring for YoP 2020, 2021 & 2022 | codewindow.in
- ColorTokens Off-Campusing | Engineering | codewindow.in
- Replicon Off-Campusing | QA Engineer | codewindow.in
- New Coding Program | Set-6 SOLVED | codewindow.in
- Protected: Testing New Styles
- Protected: Py-repl – python Compiler – Codewindow.in
- Protected: test pyscript
- Git & GitHub Tutorial – GitHub Basics Simplified in 3 Minutes – codewindow.in
- Amazon Off Campus Recruitment Drive – TA Intern – Codewindow.in
- Copy Constructor in Python – Clear Understanding in 5 Minutes – codewindow.in
- Freshworks Off Campus Recruitment Drive | Graduate Trainee | Codewindow.in
- Protected: Try About us
- Quick Heal | Software Engineer | codewindow.in
- Salient Process, Inc. | Full time Junior Business Automation Consultant | codewindow.in
- New Coding Program | Set-5 SOLVED | codewindow.in
- New Coding Program | Set-4 SOLVED | codewindow.in
- New Coding Program | Set-3 SOLVED | codewindow.in
- Git & GitHub Tutorial – Easy Git Commands Part 2 – codewindow.in
- New Coding Program | Set-2 SOLVED | codewindow.in
- New Coding Program | Set-1 SOLVED | codewindow.in
- Git & GitHub Tutorial – Easy Git Commands Part 1 – codewindow.in
- Git & GitHub Tutorial – Git Basics Simplified in 5 MINUTES – codewindow.in
- DXC Technology Off-Campusing | Associate Professional Software Engineer | codewindow.in
- HCL Off-Campusing | Technical troubleshooting | codewindow.in
- Cvent Off-Campusing | Associate Product Consultant | codewindow.in
- Dell Off-Campusing | Software Engineer | codewindow.in
- Tata Elxsi Off-Campusing | Design Engineer | codewindow.in
- Wipro Off-Campusing | Wipro’s Work Integrated Learning Program (WILP) | codewindow.in
- Harman Off-Campusing | Software Engineer, Product Development | codewindow.in
- Boeing Off-Campusing | Programmer Analyst (Java Full Stack) | codewindow.in
- Applications Of Machine Learning In Businesses | codewindow.in
- Hewlett Packard Off Campusing | Test Tool Developer | codwindow.in
- Tech Mahindra Aptitude Solve | Set-B | Part II | codewindow.in
- Tech Mahindra Aptitude Solve | Set-B | Part I | codewindow.in
- Shell Off-Campusing | Business Analyst | codewindow.in