-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from devagn611/devagn611-patch-2
pattern_upload_c
- Loading branch information
Showing
10 changed files
with
357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
|
||
int rows = 5; | ||
for (int i = 0; i < rows; i++) | ||
{ | ||
|
||
for (int j = 0; j < 2 * i; j++) | ||
{ | ||
printf(" "); | ||
} | ||
for (int k = 0; k < rows - i; k++) | ||
{ | ||
printf("* "); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
|
||
int rows=5; | ||
for (int i = 0; i < rows; i++) | ||
{ | ||
for (int j = 0; j < rows-i ; j++) | ||
{ | ||
printf("*"); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
|
||
int rows = 5; | ||
for (int i = 0; i < rows; i++) | ||
{ | ||
|
||
for (int j = 0; j < rows + i; j++) | ||
{ | ||
printf(" "); | ||
} | ||
for (int k = 0; k < rows - i; k++) | ||
{ | ||
printf("* "); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
//extra | ||
// int main() | ||
// { | ||
// int rows = 5; | ||
|
||
|
||
// for (int i = 0; i < rows; i++) { | ||
|
||
|
||
// for (int j = 0; j < 2 * i; j++) { | ||
// printf(" "); | ||
// } | ||
|
||
// for (int k = 0; k < 2 * (rows - i) - 1; k++) { | ||
// printf("* "); | ||
// } | ||
// printf("\n"); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
|
||
int rows = 5; | ||
for (int i = 0; i < rows; i++) | ||
{ | ||
|
||
for (int j = 0; j < rows - i; j++) | ||
{ | ||
printf(" "); | ||
} | ||
for (int k = 0; k < rows; k++) | ||
{ | ||
printf("* "); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
// static approach | ||
// int rows = 5; | ||
|
||
// for (int i = 0; i < rows; i++) | ||
// { | ||
|
||
// for (int l = 0; l < rows - i; l++) | ||
// { | ||
// if (l == 0) | ||
// { | ||
// printf(" "); | ||
// } | ||
// printf(" "); | ||
// } | ||
// for (int m = 0; m <= i; m++) | ||
// { | ||
// printf("* "); | ||
// } | ||
// printf("\n"); | ||
// } | ||
// for (int i = 0; i < rows; i++) | ||
// { | ||
// for (int j = 0; j < rows + i; j++) | ||
// { | ||
// printf(" "); | ||
// } | ||
// for (int k = 0; k < rows - i; k++) | ||
// { | ||
// printf("* "); | ||
// } | ||
// printf("\n"); | ||
// } | ||
// return 0; | ||
|
||
// dynamic one | ||
int n = 5; | ||
|
||
|
||
for (int i = 0; i < 2 * n - 1; i++) { | ||
// the row number | ||
int comp; | ||
if (i < n) { | ||
comp = 2 * (n - i) - 1; | ||
} | ||
else { | ||
comp = 2 * (i - n + 1) + 1; | ||
} | ||
|
||
// space | ||
for (int j = 0; j < comp; j++) { | ||
printf(" "); | ||
} | ||
|
||
for (int k = 0; k < 2 * n - comp; k++) { | ||
printf("* "); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// #include <stdio.h> | ||
|
||
// int main() | ||
// { | ||
// int rows = 5; | ||
// for (int i = 0; i < rows; i++) | ||
// { | ||
|
||
// for (int j = 0; j < (rows - i); j++) | ||
// { | ||
// printf(" "); | ||
// } | ||
|
||
// for (int k = 0; k <= i; k++) | ||
// { | ||
// printf("* "); | ||
// } | ||
// for (int j = 0; j < (rows - i) ; j++) | ||
// { | ||
// printf(" "); | ||
// } | ||
// printf("\n"); | ||
// } | ||
// return 0; | ||
// } | ||
|
||
|
||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int rows = 5; | ||
for (int i = 0; i < rows; i++) | ||
{ | ||
|
||
for (int j = 0; j < (rows - i); j++) | ||
{ | ||
printf(" "); | ||
} | ||
|
||
for (int k = 0; k <= i; k++) | ||
{ | ||
printf("* "); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int rows = 5; | ||
for (int i = 0; i < rows; i++) | ||
{ | ||
|
||
for (int j = 0; j < 2 * (rows - i) - 1; j++) | ||
{ | ||
printf(" "); | ||
} | ||
|
||
for (int k = 0; k <= i; k++) | ||
{ | ||
printf("* "); | ||
} | ||
for (int j = 0; j < 2 * (rows - i) - 1; j++) | ||
{ | ||
printf(" "); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
|
||
for (int i = 5; i < 0; i--){ | ||
printf(" "); | ||
for (int j = i; j < i; j--) | ||
{ | ||
printf("%d", j+1); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <stdio.h> | ||
|
||
void bubbleSort(int arr[], int n) { | ||
for (int i = 0; i < n-1; i++) { | ||
for (int j = 0; j < n-i-1; j++) { | ||
if (arr[j] > arr[j+1]) { | ||
int temp = arr[j]; | ||
arr[j] = arr[j+1]; | ||
arr[j+1] = temp; | ||
} | ||
} | ||
} | ||
} | ||
|
||
int secondLargest(int arr[], int n) { | ||
if (n < 2) return -1; // size is not enough | ||
// final result | ||
for (int i = n-2; i >= 0; i--) { | ||
if (arr[i] != arr[n-1]) { | ||
return arr[i]; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
int main() { | ||
int arr[] = {12, 35, 10000, 1, 34, 10000}; | ||
int n = sizeof(arr) / sizeof(arr[0]); | ||
bubbleSort(arr, n); | ||
int result = secondLargest(arr, n); | ||
|
||
if (result == -1) { | ||
printf("There is no second largest element\n"); | ||
} else { | ||
printf("The second largest element is %d\n", result); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
|
||
|
||
|
||
|
||
// #include <stdio.h> | ||
// #include <limits.h> | ||
|
||
// int findSecondLargest(int arr[], int size) { | ||
// if (size < 2) { | ||
// printf("Array should have at least two elements.\n"); | ||
// return INT_MIN; | ||
// } | ||
|
||
// int firstLargest, secondLargest; | ||
// firstLargest = secondLargest = INT_MIN; | ||
|
||
// for (int i = 0; i < size; i++) { | ||
// if (arr[i] > firstLargest) { | ||
// secondLargest = firstLargest; | ||
// firstLargest = arr[i]; | ||
// } else if (arr[i] > secondLargest && arr[i] != firstLargest) { | ||
// secondLargest = arr[i]; | ||
// } | ||
// } | ||
|
||
// if (secondLargest == INT_MIN) { | ||
// printf("There is no second largest element.\n"); | ||
// return INT_MIN; | ||
// } | ||
|
||
// return secondLargest; | ||
// } | ||
|
||
// int main() { | ||
// int arr[] = {12, 35, 1, 10, 34, 100}; | ||
// int size = sizeof(arr) / sizeof(arr[0]); | ||
|
||
// int secondLargest = findSecondLargest(arr, size); | ||
|
||
// if (secondLargest != INT_MIN) { | ||
// printf("The second largest element is %d\n", secondLargest); | ||
// } | ||
|
||
// return 0; | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdio.h> | ||
|
||
int main(int argc, char const *argv[]) | ||
{ | ||
|
||
int rows = 5; | ||
for (int i = 0; i < rows; i++) | ||
{ | ||
|
||
for (int j = 0; j < rows + i; j++) | ||
{ | ||
printf(" "); | ||
} | ||
for (int k = 0; k < rows - i; k++) | ||
{ | ||
printf("* "); | ||
} | ||
printf("\n"); | ||
} | ||
return 0; | ||
} |