0% found this document useful (0 votes)
62 views

Printing Pattern Using Loops - HackerRank

The document describes a coding challenge to print a pattern of numbers from 1 to the given input integer in a specified format. It provides the problem statement, input and output formats with sample inputs and outputs, and an example C code solution to the problem.

Uploaded by

uditanshu2605
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Printing Pattern Using Loops - HackerRank

The document describes a coding challenge to print a pattern of numbers from 1 to the given input integer in a specified format. It provides the problem statement, input and output formats with sample inputs and outputs, and an example C code solution to the problem.

Uploaded by

uditanshu2605
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

2

Prepare C Conditionals and Loops Printing Pattern Using Loops Exit Full Screen View 
 
  

Print a pattern of numbers from to as shown below. Each


285 more
Change Theme pointsCto get your gold badge!
Language:
Printing Pattern Using Loops 
of the numbers is separated by a single space.
Rank: 132871 | Points: 215/500
C language
Problem

4 #include <stdlib.h> 
5
4 4 4 4 4 4 4
6 int main()
4 3 3 3 3 3 4
7 {
4 3 2 2 2 3 4
8
4 3 2 1 2 3 4
4 3 2 2 Pattern
2 3 4
9 int n; 
Your Printing Using Loops submission
10 got 30.00 points. &n);
scanf("%d", Share Tweet
4 3 3 3 3 3 4
11 int m= 2*n - 1;
4You
4 4are
4 4 now
4 4 285 points away from the gold level for your c badge.
Submissions

12 for(int row=0; row<m; row++){


Try the next challenge |13Try a Random
for(int col=0; col<m; col++){
Challenge
Input Format 14 int min = row<col? row:col;
15 min=min<m-row? min:m-row-1;
The input will contain a single integer . 16 min=min<m-col? min:m-col-1;
17 printf("%d ",n-min);
Problem
Constraints Submissions Leaderboard 18 }
19 printf("\n");
20 }
Leaderboard

21 return 0;
Sample Input 0 22 }
Line: 10 Col: 21
2

 Upload Code as File Run Code Submit Code


Sample Output 0
Test against custom input

2 2 2
Discussions

2 1 2
2 2 2
You have earned 30.00 points!
You are now 285 points away from the gold level for your c badge.
Sample Input 1
5% 215/500

Sample Output 1

5
5
5
4
5
4
5
4
5
4
5
4
5
4
5 5
4 5
Congratulations
5 4 3 3 3 3 3 4 5 You solved this challenge. Would you like to Next Challenge
5 4 3 2 2 2 3 4 5 challenge your friends?
5 4 3 2 1 2 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 3 3 3 3 4 5
5 4 4 4 4 4 4 4Blog
5 | Scoring | Environment | FAQ | About Us | Support | Careers | Terms Of Service | Privacy Policy
5 5 5 5 5 5 5 5 5

You might also like