Category Archives: C Programs

C Programs

C Program to Print Size of int, float, double and char

In this tutorial, we will learn to create a program that finds the size of various data types such as int, float, double and char in C programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C Data Types
  • C Variables
  • C Input Output

Program to Print Size of int, float, double and char

In this program we will find the size of various data types such as int, float, double and char using sizeof operator. In C Programming, the sizeof operator returns the amount of the memory allocated to a variable of specific datatype such as int, float, double and char. In this program we will first declare and initialize a set variables each one of different data type. Later in the program we will display size of various data types such as int, float, double and char.

Output:-

C-Program-to-Print-Size-of-int-float-double-and-char

In the above program, we have first declared and initialized a set variables required in the program.

  • intVar = it is a variable of integer data type
  • floatVar = it is a variable of float data type
  • doubleVar = it is a variable of double data type
  • charVar = it is a variable of char data type

Later in the program we will find the size of various data types such as int, float, double and char using sizeof operator and will print using printf statement.

C Program to Find Quotient and Remainder

In this tutorial, we will learn to create a program to find the quotient and remainder when an integer number is divided by another integer number using C programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C Data Types
  • C Variables
  • C Input Output
  • C Operators

Program to Find Quotient and Remainder

In this program we will find quotient and remainder when an integer number is divided by another integer number. In this program user is first asked to enter two integers (dividend and divisor). Next, we will compute the quotient and remainder based on the input numbers. Later in the program we will display quotient and remainder.

Output:-

C-Program-to-Find-Quotient-and-Remainder

In the above program, we have first declared and initialized a set variables required in the program.

  • num1 = it holds the dividend value
  • num2 = it holds the divisor value
  • quotient = it holds the quotient
  • remainder = it holds the remainder

In the next statement user will be prompted to enter the two integer number values which will be assigned to variable ‘num1’ and ‘num2’ respectively. Next,we will computes quotient using division operator ( / ) and remainder using modulus operator ( % ). Finally, we will be displaying the quotient and remainder of the provided numbers using printf statement with corresponding format specifier.

Program to find Quotient and Remainder using function

In this program we will find quotient and remainder of given numbers using function. We would first declared and initialized the required variables. Next, we would prompt user to input two integers (divisor and dividend) and the quotient and the remainder computed using user defined function and later we will display quotient and the remainder.

Output:-

C-Program-to-Find-Quotient-and-Remainder

In the above program, we have first defined two function as following:

findQuotient() :- Function to computer quotient

findRemainder() :- Function to computer remainder

Next, we have declared and initialized a set variables required in the program.

  • num1 = it holds the dividend value
  • num2 = it holds the divisor value
  • quotient = it holds the quotient
  • remainder = it holds the remainder

In the next statement user will be prompted to enter the two integer number values which will be assigned to variable ‘num1’ and ‘num2’ respectively. Next,we will calling findQuotient() and findRemainder() to compute and return quotient and remainder respectively. We have assigned resultant quotient and remainder to ‘quotient’ and ‘remainder’ variables respectively.Finally, we will be displaying the quotient and remainder of the provided numbers using printf statement with corresponding format specifier.

C Program to Print ASCII Value of a Character

In this tutorial, we will learn to create a program to print ASCII value of a character in C programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C Data Types
  • C Variables
  • C Input Output

What Is ASCII value of a Character?

ASCII value is typically a numeric representation of the English characters (an integer number between 0 and 127) rather than that character itself. This integer value is referred as ASCII code of the character. For example, the ASCII value of uppercase ‘A’ is 65. This means when you assign ‘A’ to a character variable, 65 is stored in the variable rather than ‘A’ itself.

Program to Print ASCII Value of a Character

In this program we will print ASCII value of a character entered by the user. We would first declared and initialized the required variables. Next, we would prompt user to input a character. Later in the program we will display the ASCII value of the user specified character.

Output 1:-

C-Program-to-Print-ASCII-Value-of-Character-1

Output 2:-

C-Program-to-Print-ASCII-Value-of-Character-2

In the above program, we have first declared and initialized a set variables required in the program.

  • ch = it holds the character value entered by user

In the next statement user will be prompted to enter a character values which will be assigned to variable ‘ch’. Next, we will be displaying the ASCII value of the character using integer format specifier(%d) in printf statement.

C Program to Multiply two Floating Point Numbers

In this tutorial, we will learn to create a program to multiply two floating point numbers using C programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C Variables
  • C Data Types
  • C Input Output
  • C Operators
  • C Function

Program to Multiply two Floating Point Numbers

In this program we will multiply two floating point numbers entered by user. We would first declared and initialized the required variables. Next, we would prompt user to input two floating point numbers. Later in the program we will multiply the numbers entered by user. We will then display the result to user.

Output:-

C-Program-to-Multiply-two-Floating-Point-Numbers

In the above program, we have first declared and initialized a set variables required in the program.

  • n1 = it holds the first float number
  • n2 = it holds the second float number
  • product = it holds the product of n1 and n2

In the next statement user will be prompted to enter the two floating point number values which will be assigned to variable ‘n1’ and ‘n2’ respectively. Next, we will perform multiplication of both float numbers numbers (n1 and n2) and assign result to product. Now, we will be displaying the multiplication result of two floating point numbers using printf statement.

Program to multiply two numbers using function

In this program we will multiply two floating point numbers entered by user. We would first declared and initialized the required variables. Next, we would prompt user to input two floating point numbers. Later in the program we will multiply using a user defined function and display the product of the float numbers.

Output:-

C-Program-to-Multiply-two-Floating-Point-Numbers-using-function

In the above program, We have defined a user defined function called multiply(), which means to accept two float numbers and return product of the numbers passed as parameters.

Next, we have declared and initialized a set variables required in the program.

  • n1 = it holds the first float number
  • n2 = it holds the second float number
  • product = it holds the product of n1 and n2

In the next statement user will be prompted to enter the two floating point values which will be assigned to variable ‘n1’ and ‘n2’ respectively. Next, we have called multiply function and assigned its return value to ‘product’. Now, we will be displaying the product of two float numbers using printf statement.

C Program to check number is even or odd

In this tutorial, we will learn to create a program to check whether a given number is even or odd using C programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C Operators
  • C if else statement

How to check number is even or odd

An integer number that is exactly divisible by 2 is known as even number, example: 0, 8, -24. Programmatically, we can check number is even or add using modulus (%) operator. If modulus 2 of any integer number is equals to 0 then, the number is even otherwise odd.

Program to check number is even or odd

In this program we will check a number entered by user is even or odd using modulus (%) operator. We would first declared and initialized the required variables. Next, we would prompt user to input an integer number. Later in the program we will check number entered by user is even or odd using modulus (%) operator. We will then display message number is even or odd.

Output 1:-

C-Program-to-check-number-is-even-or-odd-11

Output 2:-

C-Program-to-check-number-is-even-or-odd-2

In the above program, we have first declared and initialized a set variables required in the program.

  • num = it holds the input integer number

In the next statement user will be prompted to enter an integer number to check is assigned to variable ‘num’. In the next statement we check modulus 2 of integer number is equals to 0 or not i.e. if(num % 2 == 0) then the number is even otherwise odd. Now, we will be displaying the number is even or odd.

Program to check number is even or odd Using Bitwise operator

In this program we will check a number entered by user is even or odd using bitwise(&) operator. We would first declared and initialized the required variables. Next, we would prompt user to input an integer number. Later in the program we will check number entered by user is even or odd using bitwise(&) operator. We will then display message number is even or odd.

Output 1:-

C-Program-to-check-number-is-even-or-odd-11

Output 2:-

C-Program-to-check-number-is-even-or-odd-2

In the above program, we have first declared and initialized a set variables required in the program.

  • num = it holds the input integer number

In the next statement user will be prompted to enter an integer number to check is assigned to variable ‘num’. In the next statement we check number is even or odd using bitwis(&) operator i.e. if(num & 1 == 1) then the number is odd otherwise even. Now, we will be displaying the number is even or odd.

C program to add two numbers using function

In this tutorial, we will learn to create a program to add two integer numbers using function in C programming.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C Data Types
  • C Variables
  • C Input Output
  • C Operators
  • C Function

Program to Add Two Numbers

In this program we will add two integer numbers entered by the user. We would first declared and initialized the required variables. Next, we would prompt user to input two integer numbers. Later in the program we will add the numbers using a user defined function and display the sum of the numbers.

Output:-

C-Program-to-Add-Two-Numbers

In the above program, we have first declared and initialized a set variables required in the program.

  • num1 = it holds the first integer number value
  • num2 = it holds the second integer number value
  • num3 = it holds the return value of the sum function

In the next statement user will be prompted to enter the two integer number values which will be assigned to variable ‘num1’ and ‘num2’ respectively. Next, we have called sum function and assigned its return value to ‘num3’. Now, we will be displaying the sum of two integer numbers using printf statement. Later in the last section we have defined a user defined function called sum(), which means to accept two integer numbers and return sum of the numbers passed as parameters.

C Program to Add Two Numbers

In this tutorial, we will learn to create a program to add two integer numbers using C programming language.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C Data Types
  • C Variables
  • C Input Output
  • C Operators

Program to Add Two Numbers

In this program we will add two integer numbers entered by the user. We would first declared and initialized the required variables. Next, we would prompt user to input two integer numbers. Later in the program we will add the numbers and display the sum of the numbers.

Output:-

C-Program-to-Add-Two-Numbers

In the above program, we have first declared and initialized a set variables required in the program.

  • num1 = it holds the first integer number value
  • num2 = it holds the second integer number value
  • sum = it holds the sum of the number1 and number2

In the next statement user will be prompted to enter the two integer number values which will be assigned to variable ‘num1’ and ‘num2’ respectively. Next, we will perform addition of both integer numbers (num1 and num2) and assign result to sum. Now, we will be displaying the sum of two integer numbers using printf statement.

C Program for Declaring a variable and Printing Its Value

In this tutorial, we will learn to create a program where we will be declaring a variable and printing its value using C programming language.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C Variables
  • C Data Types
  • C Input Output

Program for Declaring a variable and Printing Its Value

In this program, we will declare both integer and floating type variables and print their values using printf function.

Output:-

C-Program-for-Declaring-variable-and-Printing-Its-Value

In the above program, we have first declared and initialized a set of both integer and floating type variables.

  • a = integer type variable initialized with 5
  • b = integer type variable initialized with 10
  • c = float type variable initialized with 5.2
  • d = float type variable initialized with 20.5

In the next section we have some printf statements to print values of the integer variables using integer format specifier(%d) and values of float variables using float format specifier(%f).

C Program to Print Hello World Multiple Times

In this tutorial, we will learn to create a program to print “Hello World” multiple times using for loop C programming language.You can also use While Loop, or Do While to do the same task.

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • C printf
  • C for loop
  • C while loop
  • C do while loop

Program to Print Hello World Multiple Times

In this program we will print “Hello World” multiple time using for loop. We would first declared and initialized the required variables. Next, we would prompt user to input number of time you want print “Hello World”. Later we will print same “Hello World” string for number of time input by user.

Output:-

c-program-to-print-hello-world-multiple-time-using-for-loop

In the above program, we have first declared and initialized a set variables required in the program.

  • n = take number by user to print message.
  • i = iterator to loop through.

In the next statement user will be prompted to enter a number which will be assigned to variable ‘n’. Now we will loop through the iterator ‘i’. Inside the for loop we have print statement to print “Hello World. This will be repeated until it print “Hello World” required number of times.

C Program To Print Hello World

C Program To Print Hello World

The C “Hello World” program is a simplest program that will display some text on the screen. The C “Hello world” program is a simple yet complete program for beginners that illustrates the basic syntax of any programming language. The C “Hello world” program gives you a way to test systems and programming environment. Let’s have a look at the program first.

Note:- The printf() is a function that tells C Compiler to display or output the content inside the parentheses.

Output:-

c_program_to_print_hello_world