C program to print alphabets from a to z

Category: C Program

C program to print alphabets from a to z using while loop and for loop with char data type as well as int data type.

C program to print alphabets from a to z (using char data type and for loop)

#include <stdio.h>

void main()
{
    char ch;
    printf("Alphabets from a - z\n");
    for (ch = 'a'; ch <= 'z'; ch++)
        printf("%c\n", ch);
}

C program to print alphabets from a to z (using int data type and for loop)

#include <stdio.h>

void main()
{
    int i;
    printf("Alphabets from a - z\n");
    for (i = 97; i <= 122; i++)
        printf("%c\n", i);
}

C program to print alphabets from a to z (using char data type and while loop)

#include <stdio.h>

void main()
{
    char ch = 'a';
    printf("Alphabets from a - z\n");
    while (ch <= 'z')
    {
        printf("%c\n", ch);
        ch++;
    }
}

C program to print alphabets from a to z (using int data type and while loop)

#include <stdio.h>

void main()
{
    char i = 97;
    printf("Alphabets from a - z\n");
    while (i <= 122)
    {
        printf("%c\n", i);
        i++;
    }
}

Output

Alphabets from a - z
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

Recommended Posts