Alphabets

C program to display all Alphabets in given range using loops

C program to display all Alphabets in given range using loops

In this article, we will discuss the concept of C program to display all Alphabets in given range using loops

In this post, we are going to learn how to write a program to  print all alphabets in given range using  for, while and do-while  loop in C language

Code to display all Alphabets in given range

Code to print all alphabets in given range using for loop

In this code, we are going to learn how to print all alphabets in given range using for loop in C language

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char i,ch1,ch2;//declare char variables
    printf("Enter the two Alphabet: ");
    //ask range of alphabets from ujser
    scanf("%c %c",&ch1,&ch2);
    //Reading two alphabets given by user

printf("All Alphabets of between %c and %c : ",ch1,ch2);
    for(i=ch1; i<=ch2; i++){
     printf("%c ",i);
//display range of Alphabets with space using for loop
}
getch();
    return 0;
}

When the above code is executed, it produces the following result

case 1

Enter the two Alphabet: F
M
All Alphabets of between F and M :
F  G  H  I  J  K  L  M

Case 2

Enter the two Alphabet: c
i
All Alphabets of between a and e :
c  d  e  f  g  h  i

 

Code to print all alphabets in given range using while loop

In this code, we are going to learn how to print all alphabets in given range using while loop in C language

Program 2

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char i,ch1,ch2;//declare char variables
    printf("Enter the two Alphabet: ");
    //ask range of alphabets from user
    scanf("%c %c",&ch1,&ch2);
    //Reading two alphabets given by user

    printf("All Alphabets of between %c and %c : \n",ch1,ch2);
    i=ch1;
    while(i<=ch2){
     printf("%c ",i);
//display range of Alphabets with space using while loop
 i++;
}
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter the two Alphabet: G
N
All Alphabets of between G and N :
G  H  I  J  K  L  M  N

Case 2

Enter the two Alphabet: a
e
All Alphabets of between a and e :
a  b  c  d  e

 

Code to print all alphabets in given range using do-while loop

In this code, we are going to learn how to print all alphabets in given range using do-while loop in C language

Program 3

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char i,ch1,ch2;//declare char variables
    printf("Enter the two Alphabet: ");
    //ask range of alphabets from user
    scanf("%c %c",&ch1,&ch2);
    //Reading two alphabets given by user

    printf("All Alphabets of between %c and %c : \n",ch1,ch2);
    i=ch1;
    do{
     printf("%c ",i);
//display range of Alphabets with space using do-while loop
 i++;
}while(i<=ch2);
getch();
    return 0;
}

When the above code is executed, it produces the following result

Case 1

Enter the two Alphabet: I
T
All Alphabets of between I and T :
I  J  K  L  M  N  O  P  Q  R  S  T

Case 2

Enter the two Alphabet: r
y
All Alphabets of between I and T :
r  s  t  u  v  w  x  y


Suggested for you

For loop in C language

while loop in c language

do-while loop in c language

Operator in C language

One dimensional array in C language

 

Similar post

Java program to print all alphabets in given range

C program to print all alphabets in given range

C++ program to print all alphabets in given range

 

Java program to print all alphabets using loops

C program to print all alphabets using loops

C++ program to print all alphabets using loops

 

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

3 months ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

3 months ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.