Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 플로이드-워셜
- 구현
- 분할정복
- 에라토스테네스의 체
- DFS
- 우선순위큐
- GROUP BY
- 백트래킹
- 서브쿼리
- 자료구조
- 트리
- 해시
- DP
- 다이나믹프로그래밍
- join
- 크루스칼
- 시뮬레이션
- 투포인터
- 다이나믹 프로그래밍
- 그리디
- MST
- 재귀
- 수학
- 누적합
- 그래프 이론
- 그래프 탐색
- 다시
- 다익스트라
- BFS
- 브루트포스
Archives
- Today
- Total
기록하고 까먹지 말기
과제9 - Pointer Dynamic (6 ~ 9) 본문
#include <stdio.h>
#include <stdlib.h>
int main(){
int n, i= 0; // declaring variables
int smallest ; // smallest float
printf("Enter the total number of elements: ");
scanf("%d", &n); // enter size of inputs
int* ptr = (int*)malloc(n*sizeof(int)); // declaring array with memory allocation
for(i=0; i<n; i++){
scanf("%d", (ptr+i)); // entering numbers
// finding smallest number in entered values
if(i == 0)
smallest = *(ptr+i);
if(smallest > *(ptr+i))
smallest = *(ptr+i);
}
// printing output
printf("Smallest element is %d", smallest);
free(ptr); // erasing allocatied memory
return 0;
}
#include <stdio.h>
int main(){
// decaring variables
int n, i, j, k = 0;
printf("Enter number of rows : ");
scanf("%d", &n); // inputs total rows
int arr[100][100] = {0, }; // initializing array
arr[0][0] = 1; // first row's value
// setting Paskal's triangles
for(i=1; i<n; i++){
for(j=0; j<=i; j++){
if(j == 0 || j == i){
arr[i][j] = 1; // the value in first or last column of row is 1
continue;
}
arr[i][j] = arr[i-1][j-1] + arr[i-1][j]; // setting value under Pascal's rule
}
}
// printing output
for(i=0; i<n; i++){
for(k=1; k<(n-i); k++)
printf(" "); // space before printing values of elements
for(j=0; j<=i; j++){
printf("%d ", arr[i][j]); // printing elements
}
printf("\n"); // going to next line
}
return 0;
}
참고자료 : https://ko.wikipedia.org/wiki/%ED%8C%8C%EC%8A%A4%EC%B9%BC%EC%9D%98_%EC%82%BC%EA%B0%81%ED%98%95
#include <stdio.h>
int main(){
// initializing variables and array A and B
int a[3][3] = {0, };
int b[3][3] = {0, };
int i, j = 0;
// getting input elements from user
printf("Enter elements in matrix A of size 3x3:\n");
for(i=0; i<3; i++){
for(j=0; j<3; j++)
scanf("%d", &a[i][j]);
}
printf("\nEnter elements in matrix B of size 3x3:\n");
for(i=0; i<3; i++){
for(j=0; j<3; j++)
scanf("%d", &b[i][j]);
}
// printing the output based on sample below with calculating sum between two metrices
printf("\nSum of matrices A+B = \n");
for(i=0; i<3; i++){
for(j=0; j<3; j++){
printf("%d ", a[i][j]+b[i][j]); // printing with calculating
}
printf("\n"); // goint new lines
}
return 0;
}
#include <stdio.h>
int main(){
// initializing variables and array A and B
int a[3][3] = {0, };
int b[3][3] = {0, };
int i, j = 0;
// getting input elements from user
printf("Enter elements in matrix A of size 3x3:\n");
for(i=0; i<3; i++){
for(j=0; j<3; j++)
scanf("%d", &a[i][j]); // entering Matrix A
}
printf("\nEnter elements in matrix B of size 3x3:\n");
for(i=0; i<3; i++){
for(j=0; j<3; j++)
scanf("%d", &b[i][j]); // Entering Matrix B
}
for(i=0; i<3; i++){
for(j=0; j<3; j++){
if(a[i][j] != b[i][j]){ // there is uncoindicence between a[i][j] and b[i][j]
printf("\nMatrix A is not equal to Matrix B"); // printing message that they are not same
return 0; // then finish program
}
}
}
printf("\nMatrix A is equal to Matrix B"); // all coincidence -> printing message that they are same
return 0;
}
'전공 > C' 카테고리의 다른 글
과제11 - final (1) (0) | 2021.06.22 |
---|---|
과제10 - StructUnion (1 ~ 7) (0) | 2021.06.22 |
과제9 - Pointer Dynamic (1 ~ 5) (0) | 2021.06.22 |
과제8 - Pointer Array (6 ~ 10) (0) | 2021.06.22 |
과제8 - Pointer_Array (1 ~ 5) (0) | 2021.06.22 |