Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing pattern solution #118

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions HackerRank Problems/C programs/PointersInC.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>

void update(int *a,int *b) {
int x, y;
x = *a + *b;
y = *a - *b;
*a = x;
*b = abs(y);
}

int main() {
int a, b;
int *pa = &a, *pb = &b;

scanf("%d %d", &a, &b);
update(pa, pb);
printf("%d\n%d", a, b);

return 0;
}
25 changes: 25 additions & 0 deletions HackerRank Problems/C programs/PrintingPatternUsingLoops.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main()
{

int n;
scanf("%d", &n);
// Complete the code to print the pattern.

int len = n*2 - 1;
for(int i=0;i<len;i++){
for(int j=0;j<len;j++){
int min = i < j ? i : j;
min = min < len-i ? min : len-i-1;
min = min < len-j-1 ? min : len-j-1;
printf("%d ", n-min);
}
printf("\n");
}
return 0;
}