Code ∣ Part 1 done

 
 

It has been half a month since I was able to complete the part 1 of C Language book. So far it has been great, I was able to learn fundamentals of coding C language easily (The name of the book is called: 열혈강의 C 언어 본색 - 박정민). I definitely recommend this book for any newbie programmer who is planning to start learning C language, except that this book is in Korean.

 
 

Below, I would like to share few codes that I learn during studying C language with this book. I found some of the codes useful and very functional and you can apply to do some very simple task (no big deal, it is a code where you can do simple arithmetic and calculations).

 
 

 

A program which changes USD into KW (Korean Won):

#include <stdio.h>


int main()
{
 

int USD, Won;

// 1USD = 1,058 WON
 

printf("insert a USD currency value : \n");
scanf("%d", &USD); 

Won = USD*1058;

printf("달러를 한화로~ : %d원 \n", Won); 

 

return 0;
 

}

OR

#include <stdio.h>
 

int main()
{

int KRW=1058;
int USD;

printf("얼마나 환전 하시겠습니까? <단위: 달러> : ");
scanf("%d", &USD);

KRW *= USD; 
 

//여기서부터 printf("%d달러 => %d원 \n", USD, USD*KRW); 도 사용가능.


printf("%d달러 => %d원\n",USD, KRW);


return 0;
 

}
 

 

 

 

A program which shows a biggest value when three values are inputted:

#include <stdio.h>


int main()
{
 

int a, b, c;
int result1;

printf("Insert three numerical values : \n");
scanf("%d, %d, %d", &a, &b, &c);

result1 = (a > b) ? (a > c) ? a : c : (b > c) ? b : c;

printf("가장 큰 값은 : %d \n", result1);

return 0;

}

 OR

#include <stdio.h>


int main()
{

int a,b,c;
int result1, result2, result3;

printf("첫번째 정수를 입력하세요. :");
scanf("%d", &a);
printf("두번째 정수를 입력하세요. :");
scanf("%d", &b);
printf("세번째 정수를 입력하세요. :");
scanf("%d", &c);

result1=(a>b) ? a : b;
result2=(c>b) ? c : b;
result3=(c>a) ? result2 : result1;

printf("가장 큰 정수를 %d입니다. \n", result3);


return 0;
 

}

 

 

A program where if two numerical values where inserted, the smallest value is given, while if the values are equal, the 'equal' is shown: 

#include <stdio.h>


int main()
{
 

int a, b;
int result1, result2;

printf("input: ");
scanf("%d", &a);
printf("input: ");
scanf("%d", &b);

result1 = (a > b) ? b : a;
result2 = (a == b) ? printf("Same \n") : printf("Smallest value: %d \n", result1);

return 0;
 

}
 

 

 

A program which calculates the total time taken of a car when the radius of a track and the speed of the car is inputted:

#include <stdio.h>

int main()
{
 

int speed;
int radius;
double timetaken;
double pie = 3.14;

printf("반지름을 입력해주세요.\n >>");
scanf("%d", &radius);

printf("자동차의 속도를 입력해주세요.\n >>");
scanf("%d", &speed);

timetaken = ((2*pie*radius)/speed)*60;

printf("자동차가 한 바퀴를 완주하는데 걸리는 시간은 %.3f분 입니다.\n", timetaken);


return 0;
 

}

 

 

 

A program which finds an area of a circle and the circumference from a radius:

#include <stdio.h>

int main()
{
 

int r;
double area;
double circumference;
double pie = 3.14;

printf("반지름 값을 입력해 주세요.\n >>");
scanf("%d", &r);

area = pie*r*r;
circumference = 2*pie*r;

printf("입력하신 반지름의 원의 면적은 %.3f이고, 둘레는 %.3f입니다.\n", area, circumference);

return 0;
 

}
 

 

 

A program which shows a table of multiples from the value inputted:

#include <stdio.h>

int main()
{
 

int input=0;
int j=0;
int k=0;

printf("숫자를 입력하세요 : ");
scanf("%d", &input);

while(j<10)
{
printf("%d * %d = %d입니다.\n", input, j, k);
j++;
k=input*j;

}


return 0;
 

}


 

 

 

A program which shows the nth of alphabet from an alphabet inputted:

#include <stdio.h>

int Alpha(char n);

int main(void)
{
 

char n;
int i;

printf("알파벳을 입력하세요: ");
scanf("%c", &n);

i=Alpha(n);

printf("입력한 %c는 알파벳 순서로 %d번째 문자입니다.\n", n, i);

return 0;
 

}
int Alpha(char n)
{
 

if(n<=90)

return n-64;

else if(n>=97)

return n-96;

else

return 0;
 

}

 

 

 

A program which finds the sum of 1 to nth term:

#include <stdio.h>

int sum(int n);

int main(void)
{
 

int a;
int result;

printf("input your number = ");
scanf("%d", &a);

result=sum(a);

printf("1부터 %d까지의 합 = %d\n", a, result);

return 0;
 

}


int sum(int n)
{
 

if(n<=1)

return 1;

else

return n+sum(n-1);
 

}

 

 

 
 

These codes are few of the codes that I made after learning the basics of C programming. There are more codes that I created while learning, however I decided to show the ones that I especially found pretty fun while creating them.

Learning how to code so far has been interesting and intriguing to me. There are still lots to learn and lots to cover ahead, but I think it will be more fun as I go along and will help me be more creative in both artistic and logical dimensions.