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.

 

 
 

Beauty of Coding

 
 

Since December 2013, I started to learn a programming language due to my intense fascination of computer science and its collaboration with Art, design and technology.

I originally thought of learning computer security, however I realized that programming is a fundamental element that you need in order learn computer security, which made me decide to learn programming to begin with.

I decided to learn C language as it helps me to learn other language easily as well, such as C++ and Java, which, I heard, is other languages which is required or at least very helpful in order to learn computer security.

Starting with C

Learning a programming language is like learning a new language. Luckily the sets of rules (so far) was not that difficult to learn, and so far I was able to produce variety of programs for variety of purposes.

One thing I realized that most of the practices that I did was based on mathematical questions, writing codes to solve the maths problem. I cannot wait to see how I can apply this process to create something beyond the mathematical playground.

The Beauty of programming language

While I was learning how to do C language, I discovered that it all comes to logic and problem solving: There are sets of rules and questions, now you have to solve it - like a puzzle. 

I realized that this process require not just logical and critical thinking, but also creative and innovative thoughts to come up of solutions. Since there are unlimited number of solutions, the important thing is not whether you have solved it, but how you solved it.

This 'how' seems to be something that I was able to be fascinated and realize that creativity and artistic production does not only lies on art subjects, but also in mathematics and engineering.

The code below is one of the code that I found it beautiful, which represents a program to print the 'star: *' in pattern.

 

#include <stdio.h>

int main()
{

int i;
int j;
int k;

for(i=3; i>=0; i--)
{

for(j=3; j>i; j--)
{
printf(" ");
}

for(k=0; k<=i*2;k++)
{
printf("*");
}

printf("\n");

}


return 0;

}

 

Although it may seem insignificant when we have a look at the output of this program, we realize that the aesthetic of this piece of code due to its relationship between each sentence and the functions, linked together. 

Learning coding is so far have been a great experience for me in both tackling new areas and able to enhance my creative thinking skills as coding requires the programmer to think creative as well.

Now I realize why some people say that mathematic equations are beautiful, and why programmers are often called artist and designers. Because they are. The difference is that they use codes and programming instead of paints and brushes.