In the following program, user would be asked to enter a lower case String and the program would convert it into a Upper case String. Logic followed in the program: All lower case characters (a to z) have ASCII values ranging from 97 to 122 and their corresponding upper case characters (A to Z) have ASCII values 32 less than them. For example ‘a’ has a ASCII value 97 and ‘A’ has a ASCII value 65 (97-32). Same applies for other alphabets. Based on this logic we have written the below C program for conversion.
C program – Conversion of a String from lowercase to uppercase
/* C Program to convert Lower case * String to Upper case. * Written by: Chaitanya */ #include<stdio.h> #include<string.h> int main(){ char str[25]; int i; printf("Enter the string:"); scanf("%s",str); for(i=0;i<=strlen(str);i++){ if(str[i]>=97&&str[i]<=122) str[i]=str[i]-32; } printf("\nUpper Case String is: %s",str); return 0; }
Output:
As you can observe in the above screenshot, we have entered a lower case string(beginnersbook.com) and the program converted into a Upper case string (BEGINNERSBOOK.COM)
Leave a Reply