티스토리 뷰
이번 과제는 원하는 만큼 구구단 출력하기!!!!
아래 그림과 같다.
급하게 만들어서 약간의 오류가 있다. 알아서 수정하길 바란다.
// This source was written by Yo-han Kim (johnkim126@korea.ac.kr) // Title : Print a multiplication Table with command line argument (Programming Assignment on Operating System, Korea Univ.) #include <stdio.h> #include <stdlib.h> #include <math.h> #include <string.h> int main(int argc, char** argv){ /* - variables definition and initialization - int i : print row int j : print column int k : input argument int line : change line int count : printf until 5 rows */ int i=1,j=1,k=0; int line=1,count=1; k = atoi(argv[1]); //using function that change ascii code to integer /* using three for loop */ for(line=1;line<=k;line=line+5){ //1st for loop (change line) for(j=1;j<=k;j++){ //2nd for loop(print column to input argument) for(i=line;i<=k;i++){ //3rd for loop (print row to input argument) if(i>=j&&count<=5){ // 1st condition : check the basic rule, printf until 5 rows // basic rule : input - 2, print - 2*1=2, 2*2=4... 2*3<= No way printf(" %2d * %2d =%3d ",i,j,i*j); } else if(count<=5) { // 2st condition : print for space and design printf(" "); } count++; // increasing variable } printf("\n"); count=1; //initialization in 2nd for loop } printf("==========================================================================\n"); } printf("\n"); return 0; }
' la fermata, 개발 > C, C++' 카테고리의 다른 글
[Code] Program Counter (0) | 2019.02.19 |
---|---|
[Code] CPU load (0) | 2019.02.19 |