Translate

Friday, 21 March 2014

Program to print English alphabets in order using increment factor


Source Code :


#include<stdio.h>
#include<conio.h>
void main(void)
{
char a;
clrscr();
a=65;
printf("The first character is  : %c",a);
a++;
printf("\nThe second character is : %c",a);
a++;
printf("\nThe third character is  : %c",a);
a++;
printf("\nThe forth character is  : %c",a);
a++;
printf("\nThe fifth character is  : %c",a);
getch();
}


Here we used the increment factor to produce ( A,B,C.............)
you know the ASCII codes for the English alphabets, used that logic to create a simple program.
what we did here is that assigned a=65 , which is the code for Capital alphabet 'A' and used increment to increase the number to 66,67 which are the codes for capital B,C ... so on respectively and print using the %c  [ note if you use %d to print , it will just print the number 66.67..... ]


The sample program looks something like this.




No comments:

Post a Comment