Category Archives: C Programs

C Programs

C Program to Check Leap Year

In this tutorial, you will learn to create a c program to find given year is a leap year or not.

Prerequisites

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

  • C Operators
  • Conditional statement.
  • Basic input output .

Example:

So logic behind to check whether a year is leap or not is:
Logic of Leap Year:
If the given value is completely divisible by 4, 100 and 400 then it is a leap year.
If the given value is divisible by 4 but not  by 100 then it is a leap year.

Logic for  not a Leap Year:
If the given value is not divisible by 4 then it is not a leap year
If the given value is divisible by 4 and 100 but not divisible by 400 then it is not a leap year.

For example,

  • 1221 is not a leap year.
  • 2000 is a leap year.
  • 1890 is not  a leap year.

Program to Check given year is a Leap Year or not.

Here fist we take a year from user and with help of logical operator(&& and ,|| or) we will check multiple condition in a single if statement and get the required result.

Output

C Program to Check Leap Year

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

  • year =taking year value from user.

First of all take a value from user to check whether a year is leap or not is,
then we check if the given value is completely divisible by 4, 100 and 400 then it is a leap year.
If the given value is divisible by 4 but not  by 100 then it is a leap year.

C Program to Print a Semicolon Without Using a Semicolon

C Program to Print a Semicolon Without Using a Semicolon

In this tutorial, we will learn to create a C program that will Print a Semicolon Without Using a Semicolon in C programming.

Prerequisites

Prior to starting this tutorial, we assume that you are best aware of some basic concepts of c programming language.

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • Concepts of conditional statements.

In todays’ session, we will learn to create a program that will print a semicolon on the screen without using “;”. The semicolon is terminology for completing every statement in the c programming language. The semicolon is used for ending loops and conditional statements.

However, we won’t be using the “;” in the print statement.

With the help of this program, we can Print a Semicolon Without Using a Semicolon.

Algorithm:-

Program to Print a Semicolon Without Using a Semicolon:-

Method type 1 to print a semicolon.

Method type 2 to print a semicolon.

 

 

Output:-

Printing the semicolon.

Method 1 for printing the semicolon on the output console.

Method 2 for printing the semicolon on the output console.

 

 

C Program to Convert Number into Word

C Program to Convert Number into Word

In this tutorial, we will learn to create a C program that will convert Number into Word  using C programming.

Prerequisites

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

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • While loop in c programming.
  • Switch Case statement in C Programming.
  • Header Libraries and its usage.

Convert Number into Word

In c programming it is possible to take numerical input from the user and convert it into words  with the help of very small amount of code . The C language has many types of header libraries which has supported function in them with the help of these files the programming is easy.

With the help of this program we can Convert Number into Word.

Algorithm:-

Program to convert Number into Word:-

 

Output:-

The above program we have first initialize the required variable.

  • no = it will hold the integer value.
  • r = it will hold the value of digit.
  • sum = it will hold the sum.

Including the header files required for program.

Input number from user.

Switch Case body.

C Program to Print Without Semicolon

C Program to Print Without Semicolon

In this tutorial, we will learn to create a C program that will Print Without semicolons in C programming.

Prerequisites

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

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • Concepts of for loop.
  • Using while statement of C language.
  • Using Switch in C programming.

In the C programming language, a semicolon is used to complete any string or statement. but in today’s tutorial, we will learn to create a program that will print a statement without using semicolons. The semicolons are used to end or complete any function.

There are three methods by which we can do this.

  1. Using conditional statements.
  2. With the help of a switch case.
  3. By using looping statements.

With the help of this program, we can Print Without a Semicolon.

Algorithm 1:-

Method 2 Algorithm:-

Method 3 Algorithm:-

 

Program to Print Without a Semicolon:-

Method type 1 to print a semicolon with the help of conditional statement if.

 

Method type 2 to print a semicolon with the help of a switch.

 

Program type 3 to print a semicolon with the help of a while.

 

Output:-

Printing without the semicolon 1.

Method 2 for printing the semicolon on the output console.

Method 3 for printing the semicolon on the output console.

Code for program 1

Program 2 Code

Code For Program 3

C Program to Generate Random Numbers

In this tutorial, we will learn to create a C program that  will generate  a random number  using C programming.

Prerequisites

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

  • Basic C programming.
  • Operators.
  • Looping statements
  • For Loop.
  • Basic input/output.
  • Inbuilt library function.

What Is Random number?

Random number is are set of digits (i.e., 0, 1, 2, 3, 4, 5, 6, 7, 8, 9) arranged in irregular order.

As you can see here some random number between 1 to 10 are shown in above image we will use here a rand() function to generate 10 different random number in our our program let us see how to do that.

C Program to Generate Random Numbers.

Here in our program we are going to use rand() inbuilt function which is define in header file stdlib.h with the help of this function we genrate 10 differnet random number let have a look at program.

Output

C Program to Generate Random Numbers

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

  • no = For holding random values 
  • i = for iteration.

First of all we declare two variable i for iteration and no  for holding value provided by rand() function. Here in this program we use rand() function to generate 10 random number in our program.In our program we use for loop to print Ten different random value using rand() function at multiple times.

As we can see in above image that in each iteration the rand() function called every time gives us a new random number between 1-10 because we use range from 1-10 to print 10 different values if we want to print ten different values form 1-100  then with rand() function we have to use rand()%100 it will gives us ten different value between 1-100.

c program to calculate simple interest using function

In this tutorial, we will learn to create a C program that will Calculate Simple Interest 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 Operators.
  • C functions,
  • basic input/output.

What Is Simple interest?

 Simple interest is basically a calculation of the interest charged on a given principal amount with in a particular part of time by the bank to customer or taken by bank.

Simple Interest = (p * n * r) / 100

here,    p = Principal,

             n = Time Period or year.

             r = Rate of Interest.

Example

Let take an example of this,

p=5000,r=10,and t=1 year.

then,

Output

Algorithm

  1. Firstly define Principal, rate and Time of loans.
  2. Apply the formula.
  3. Output Simple Interest.

C Program to Calculate  Simple Interest.

First of all  we take principal ,rate and time  and pass them to function as a argument that will calculate the simple interest.let see a program for these.

Output

 

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

  • a = for taking value of Principal.
  • b = for taking value of rate.
  • c= for taking value of time.
  • p= for holding value of a.
  • r = for holding value of b.
  • t= for holding value of c.
  • si= calculate simple interest.

This program takes three  values of principal,rate and time in a,b,c from user and then passing these value in function Simple_int(a,b,c) as argument the above function after  calculating value function returns simple interest.

As shown in above figure. The value return by the function is hold by result variable and with help of result we can print the simple interest using function.

c program to calculate compound interest

In this tutorial, we will learn to create a C program that  will Calculate Compound Interest    using C programming.

Prerequisites

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

  • Arithmetic operators.
  •  Basic input/output
  • C loop statements
  • Operator precedence
  • Data types.

What Is Compound Interest?

Compound interest (or compounding interest) is an interest to the principal sum of loan or deposit by consumer or by bank to consumer, or in other words,Compound Interest is interest on interest.

CI is interest earned from the original principal +  accumulated interest.

formula for Compound Interest is.

Here,

P is principle amount.
R is the rate in Percent.
T is time in year.

C Program to Calculate Compound Interest.

Output

c program to calculate compound interest

c program to calculate simple interest

In this tutorial, we will learn to create a C program that Find Simple Interest using C programming.

Prerequisites

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

  • Basic C programming.
  • Operators.
  • Basic input/output.
  • Basic mathematics calculation.

What Is Simple interest ?

Simple interest is the interest amount given by the bank within a year to consumer or taken by bank from consumer  for a particular principal amount of money at some rate of interest. Simple Interest is a method of calculating the interest for a loan/principal amount.

Where:=>
SI = simple interest.
P = principal
R = interest rate (in percentage).
T = time duration (in years).

C Program to Calculate Simple Interest.

Output

c program to calculate simple interest

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

  • si = For calculating si.
  • p=  for principal.
  • r= for rate of interest.
  • t= for time interval in a year.

First of all we declare 4 variable si,p,r and t then by prompting user to give principal rate and time . Here in this program we get principal rate and time from user.

After accepting values of  principle, rate and time from user , we apply the formula to calculate simple interest is which  is si= (principle x rate x time) / 100. and  after calculating si we will print the Simple Interest. 

Simple Interest is a method used by mostly in Banking and Economic sectors to calculate the interest charges on loans or in saving account by Bank or Economic Sectors.

C Program to Print 1 to 10 Without Using Loop

C Program to Print 1 to 10 Without Using Loop

In this tutorial, we will learn to create a C program that will Print 1 to 10 Without Using Loop in C programming.

Prerequisites

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

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • Conditional statements in c programming.

As we all know the String is a collection of character data types. In strings, only one variable is declared which can store multiple values.In c programming language we can do all the work for multiple printing with the help of loops but in today’s tutorial we will complete the program without using the loops.

There are two ways to complete this program.

With the help of this program, we can Print 1 to 10 Without Using Loop.

Algorithm 1:-

Algorithm 2:-

Program 1 to Print 1 to 10 Without Using Loop:-

Program 2 to Print 1 to 10 Without Using Loop:-

Output:-

The above program we have printed each line manually by writing the codes.

 

Output 2:-

The above program we have first initialized the set of variables for the program.

  • i = it will hold the integer value.

User defined Function for printing.

 

Printing the numbers from the function.

Calling the user defined function.

C Program to Find Factor of a Given Number

In this tutorial, we will learn to create a C program that  will find Factors of a number  using C programming.

Prerequisites.

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

  • Operators.
  • If else statement.
  • C for Loop.
  • Basic input/output.

What Is Factor of number is?

Factors:=> So factors of a number are numbers that divide the number completely and remainder of divisor is equal to zero.

Example:->

The number 6 has four factors: 1, 2, 3,  and 6 because all this number divide the number six completely.

C Program to Find Factor of a Given Number.

In this program we will  find factor of given number  using if else statement and for loop. We would first declared and initialized the required variables. Next, we would prompt user to input the number . Later we will find factors.

Output

C Program to Find Factor of a Given Number

In this program  we will take a positive integer from user by prompting  and with the help of loop and if else statement  we will displays all the positive factors of that number.

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

  • no = It will hols number given by user.
  • j= for iteration of loop and finding  factor.

So the logic behind computing factors of a number is we will run a loop from 1 to no, increment 1  in each iteration.
The loop structure should look like this

Within the loop  in each iteration we check the condition that j is a factor of no or not. To check factor we use divisibility of number by using  modulo division

i.e. if( no % j == 0) then j is a factor of no If j is a factor of no then we will print the value of j.So we will get the required factors of given number.

C Program to Check Lower Upper Case

In this tutorial,  will learn to find  entered character is an Uppercase or in a lower case  using C programming language.

Prerequisites

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

  • Basic Programming
  • Operators.
  • looping statements
  • For Loop
  • If else statement.
  • Basic input/output.

What Is Upper and lower case.

Uppercase letters are capital letters. they usually signal reader that something is important or significant in a Text.Uppercase letters represent the beginning of a sentence or a proper noun.
uppercase letters: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z.

lowercase letters In writing, most letters are lowercase. Lowercase letters are all letters that do not begin a sentence or refer to a proper noun.Each word in this sentence other than the first word is written in lowercase.
lowercase letters: a b c d e f g h i j k l m n o p q r s t u v w x y z.

C Program to Check Lower Upper Case

Output

C Program to Check Lower Upper Case

Buzz Fizz Program in C

In this tutorial, we will learn to create a C program that  Find BUZZ FIZZ  using C programming.

Prerequisites

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

  • Operators
  • Basic C programming.
  • Basic input/output.
  • Looping statements
  • For Loop
  • If else statement.

What Is Buzz Fizz?

The concept of Buzz and Fizz is if integers between 1 to N, print “Fizz” if an integer is divisible by 3, “Buzz” if an integer is divisible by 5, and “FizzBuzz” if an integer is divisible by both 3 and 5.

Example:

A program that prints the numbers from 1 to no(suppose 15) .If number is a multiple of ‘3’ print “Fizz” instead if multiples of ‘5’ print “Buzz” and if multiple of 3 and 5 both then print “Fizz Buzz”.
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14,
Fizz Buzz.

Buzz Fizz Program in C.

In this program we will print find  Buzz Fizz  using for loop. We would first declared and initialized the required variables. Next, we would prompt user to input the number of terms. Later we will  find  Buzz Fizz series of specified number of terms.

Output

Buzz Fizz Program in C

 

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

  • no = number of terms to be printed
  • i     = for iteration of loop.

Here in this program we will print  number from 1 to no.If number is  multiple of 3, we print “Fizz” instead of the number. as you can see in image below.


And if number is multiple of 5, print “Buzz” instead of the number.


And in final case if numbers which are multiples of both 3 and 5, print “FizzBuzz” instead of the number.So in our program we take a number from user at run time,suppose user gives a number 15 then the series of fizz , buzz  and fizzbuzz is look like this.