B4Coder
0%
LessonAbout 5 min

Chapter 1 · Lesson 1 of 5

01. Your first C program

What C is, the parts every C program has (#include and main), and printf to show words on the screen.

C is one of the oldest programming languages still used everywhere: inside phones, cars, washing machines and the operating systems that run computers. Python itself is written in C. Learn C and you learn how computers really work.

Here's a whole C program. It shows one line on the screen.

C
#include <stdio.h>
int main() {    printf("Hello, World!\n");    return 0;}

It shows

Hello, World!

Every C program has the same shape. #include <stdio.h> brings in the tools for input and output, like printf. int main() is where the program starts, and everything it does goes between the curly braces { }.

printf shows text. The text goes inside double quotes, and \n at the end means new line. return 0; says the program finished well. Each instruction ends with a semicolon ;.

Your turn

1Steps

  1. 1Write a program that prints I am learning C! on its own line.

Write it in main.c. If it reads input, put the answers in Program input, under the terminal.

Use: printf()

Starting code

The editor starts empty. Copy this into it to begin, or write your own from scratch.

C
#include <stdio.h>
int main() {    // Print your line here
    return 0;}

2Expected output

It should show

I am learning C!

3Hints

Stuck? Open one hint at a time: each gives a bit more help.

Hint 1

It's one printf line, inside main, before return 0;.

Hint 2

The words go in double quotes inside the brackets: printf("…");

Hint 3

Put \n at the end of the words so the line ends, and don't forget the ; after the bracket.

Terminal

Click Run to see what your program shows, then Submit answer to check it and unlock Next.