Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

The First C Program

YASH PAL, 4 September 202219 February 2026

Armed with the knowledge about the types of variables, constants & keywords the next logical step is to combine them to form instructions However, instead of this, we would write our first C program now. Once we have done that we would see in detail the instructions that it made use of.

Before we begin with our first C program do remember the following rules that are applicable to all C programs:

  1. Each instruction in a C program is written as a separate statement Therefore a complete C program would comprise a series of statements.
  2. The statements in a program must appear in the same order in which we wish them to be executed unless, of course, the logic of the problem demands a deliberate ‘ jump ‘ or transfer of control to a statement, which is out of sequence.
  3. Blank spaces may be inserted between two words to improve the readability of the statement. However, no blank spaces are allowed within a variable, constant, or keyword.
  4. All statements are entered in small case letters.
  5. C has no specific rules for the position at which a statement is to be written That’s why it is often called a free-form language.
  6. Every C statement must end with a ; Thus ; acts as a statement terminator.

Let us now write down our first C program. It would simply calculate simple interest for a set of values representing principle, number of years, and rate of interest.

C
/*Calculation of simple interest */
main ()
{
int p, n;
float r, si; 
p = 1000;
n = 3 ; 
r = 85 ; 
/*formula for simple interest */ 
si = p * n * r / 100 ;
printf ( " %f " ,si );
}

Now a few useful tips about the program…

1. Comments about the program should be enclosed within /* */ For example, the first two statements in our program are comments.

2. Though comments are not necessary, it is a good practice to begin a program with a comment indicating the purpose of the program, its author, and the date on which the program was written.

3. Any nun of comments can be written at any place in the program For example, a comment can be written before the statement, after the statement, or within the statement as shown below:

C
/* formula */ si = p * n * r / 100;
si = p * n * r / 100, /* formula */
si = p * n * r / /* formula */ 100;

4, Sometimes it is not so obvious what a particular statement in a program accomplishes. At such times it is worthwhile mentioning the purpose of the statement ( or a set of statements ) using a comment. For example.

C
/* formula for simple interest */
si = p * n * r / 100;

5. Often programmers seem to ignore the writing of comments But when a team is building big software well-commented code is almost essential for other team members to understand it.

6. Although a lot of comments are probably not necessary in this program, it is usually the case that programmers tend to use too few comments rather than too many An adequate number of comments can save hours of misery and suffering when you later try to figure out what the program does.

8. The normal language rules do not apply to text written within / * .. * / Thus we can type this text in a small case, capital, or a combination This is because the comments are solely given for the understanding of the programmer or the fellow programmers and are completely ignored by the compiler.

9. Comments cannot be nested. For example.

C
/* Cal of Sl /* sam date 01/05/2005 */ */ is invalid.

10. A comment can be split over more than one line, as given below.

C
/* This is
a jazzy
comment */

Such a comment is often called a multi-line comment.

11. main ( ) is a collective name given to a set of statements. This name has to be main ( ), it cannot be anything else. All statements that belong to main ( ) are enclosed within a pair of braces { } as shown below.

C
main ( ) 
{ 
 statement 1;
 statement 2;
 statement 3;
} 

12. Technically speaking main ( ) is a function Every function has a pair of parentheses ( ) associated with it.

13. Any variable used in the program must be declared before using it. For example

C
int p, n ;
float r, si;

14. Any C statement always ends with a; For example

C
float r, si; 
r = 8.5;

15. In the statement

C
si = p * n * r / 100; 

* and / are the arithmetic operators. The arithmetic operators available in C are +, -, *, and /. C is very rich in operators There are about 45 operators available in C. Surprisingly there is no operator for exponentiation. a slip, which can be forgiven considering the fact that C has been developed by an individual, not by a committee.

16. Once the value of si is calculated it needs to be displayed on the screen Unlike other languages, C does not contain any instruction to display output on the screen. All output to the screen is achieved using readymade library functions. One such function is printf( ) We have used it to display on the screen the value contained in si.

The general form of the printf( ) function is

C
printf ( " < format string > " , < list of variables > );

< format string > can contain

%f for printing real values
%d for printing integer values
%c for printing character values

In addition to format specifiers like %f %d and %c, the format string may also contain any other characters. These characters are printed as they are when the printf( ) is executed:

Following are some examples of usage of the printf( ) function.

C
printf (“%f”, si);
printf (" % d % d % f % f " , p , n , r , si ); 
printf (" Simple interest = Rs . % f " , si ); 
printf (" Prin = % d InRate = % f " , p , r );

The output of the last statement would look like this…

C
Prin = 1000
Rate = 8.5

What is ‘ \ n ‘ doing in this statement? It is called newline and it takes the cursor to the next line. Therefore, you get the output split over two lines. n is one of the several Escape Sequences available in C. Right now, all that we can say is \ n ” comes in handy when we want to format the output properly on separate lines.

printf( ) can not only print values of variables, but it can also print the result of an expression. An expression is nothing but a valid combination of constants, variables, and operators Thus, 3, 3 + 2, c and a + b * c – d all are valid expressions The results of these expressions can be printed as shown below:

C
printf (" % d % d % d % d ", 3 , 3 + 2, c , a + b * c - d);

Note that 3 and c also represent valid expressions.

Read other tutorials

  • Compiling c programs
  • Reading input in c programming
c Computer Science Tutorials cC Programcomputer science

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

The First C Program
Reading Input in a C Program
Compiling C Programs
C Program to read a number and print the factorial
C Program to Print the Sum of N Natural Numbers
C Program to Print Factorial of any Given Number
C Program to Check a Prime Number or Not
C Program to Print the Power of a Given Number
C Program to Print Factors of a Given Number
C Program to Print Factorial using Recursion
C Program to find gross salary
C Program to Reverse a Given Number
C Program to Swap Two Numbers without Using a Third Variable
C Program to Calculate the sum of subjects and find the percentage
C Program to convert temperature from centigrade to Fahrenheit
C Program to find simple interest
C Program to find the area and circumference of a circle
C Program to find the sum of two numbers
C Program to find the sum of two matrices
C Program to find even/odd numbers
C Program to display a matrix
C Program to show the use of the conditional operator
C Program to find the maximum number in an array
C Program to find the greatest of 3 Numbers
C Program to show the sum and average of 10 elements of an array
C Program to print a table of any number
C Program to add two numbers using pointers
C Program to use the bitwise AND operator between the two integers
C Program to display an odd number series and find the sum
C Program to display the sum of the harmonic series
C Program to print the Fibonacci series up to 100
C Program to print a star pattern in a pyramid shape
C Program to print a star pattern in a reverse triangle shape
C Program to print a star pattern in a triangle shape
C Program to display the first 10 natural numbers and their sum
C Program to display arithmetic operations using a switch case
C Program to display weekdays using a switch statement
C Program to find the subtraction of two matrices
C Program to shift input data by two bits to the left
C Program to find occurrences of vowels, consonants, words, spaces and special characters in give sentence
C Program to merge two arrays, excluding the repeating elements
C Program to perform file operations
C Program to find a palindrome number
C Program to find the largest of two numbers using the function
C Program to show call by reference
C Program to show call by value
C Program to show a table of numbers using a function
C Program to find the factorial of a number using a function
C Program to swap two numbers using a function
C Program to find the square of a number using a function
C Program to show input and output of a string
C Program to print the powers of 2 tables for the powers 0 to 20
C Program to find the maximum number in an array using a pointer
C Program to print the multiplication table
C Program to find the transpose of a matrix
C Program to evaluate the equation y=xn
C Program to find the multiplication of two matrices
C Program to display months using enum
C Program for finding the largest number in an array
C Program for sorting the elements of an array in descending order
C Program to count the number of students in each group
C Program to evaluate a square expression and its sum
C Program for plotting of two functions
C Program of minimum cost problem
C Program to draw a histogram
C Program to print a binomial coefficient table
C Program to read a line of text
C Program to illustrate the use of the continue statement
C Program to read a string using the scanf() function
C Program to evaluate the geometric progression series
C Program for production and sales analysis
C Program to illustrate the use of the break statement
C Program to evaluate response to a multiple-choice test
C Program to print the total marks obtained by a student
C Program to calculate standard deviation
C Program to sort a list of numbers and to determine the median
C Program for finding the desired kth smallest element in an array
C Program for removing duplicate elements in an array
C Program to use functions with no arguments and no return values
C Program to sort a customer list in the alphabetical list
C Program for counting characters, words, and lines in a text
C Program to sort a list of names in alphabetical order
C Program to calculate the square and cube by using a function as an argument
C Program to use string handling functions
C Program to return only absolute values
C Program to concatenate a string
C Program to pass arguments to a user-defined function by value/reference
C Program to print the Character and Decimal value of alphabet
C Program to return more than one value from a user-defined function
C Program to count the number of characters copied into a string
C Program to show the use of user defined function
C Program to use global variables on different functions
C Program to use similar variables in different functions
C Program to define & call user-defined functions
C Program to call a user-defined function
C Program to find the power of a value using a function
C Program to use functions with arguments and return values
C Program to use functions with arguments but no return values
C Program to use the ++ operator with the return value of a function
C Program to perform multiplication and division of numbers
C Program to perform addition and subtraction of numbers
C Program to assign the return value of a function to another variable
C Program to call the function through a for loop
C Program to call the user-defined function through the switch() statement
C Program to call the user-defined function through an if statement
C Program to evaluate the function equation s = sqr(a() + b())
C Program to use modulo % with a function
Student marksheet program in C programming

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes