CONVERSION FROM UPPERCASE TO LOWER CASE USING C PROGRAM




Conversion from uppercase to lower case using c program

#include<stdio.h>
#include<string.h>
int main(){
  char str[20];
  int i;
  printf("Enter any string->");
  scanf("%s",str);
  printf("The string is->%s",str);
  for(i=0;i<=strlen(str);i++){
      if(str[i]>=65&&str[i]<=90)
       str[i]=str[i]+32;
  }
  printf("\nThe string in lower case is->%s",str);
  return 0;
}

Algorithm:

ASCII value of 'A' is 65 while 'a' is 97. Difference between them is 97 – 65 = 32
So if we will add 32 in the ASCII value of 'A' then it will be 'a' and if will we subtract 32 in ASCII value of 'a' it will be 'A'. It is true for all alphabets.
In general rule:
Upper case character = Lower case character – 32
Lower case character = Upper case character + 32





3. Write a c program to delete the all consonants from given string.

24 comments:

  1. HI..this program is not giving any output..
    plz check it

    ReplyDelete
  2. You have to include the header file coz string functions are being used.

    ReplyDelete
  3. need fflush(stdin) n getchar() there.. n change into lower case right? please make a correction..

    ReplyDelete
  4. hey this programm is not returning upper case .please correct it..

    ReplyDelete
  5. This program doesn't convert into upper case while it converts only uppercase to lower case

    ReplyDelete
  6. scanf statement does not contain &

    ReplyDelete
  7. Hey! This doesn't convert lower case to upper case, it only convert upper case to lower case.please check it.

    ReplyDelete
  8. HEY!this programm is not returning upper case .please correct it..

    ReplyDelete
  9. Hi ! What would be the program without using function strlen.

    ReplyDelete
  10. Hy!I think this program is not correct.Please check it once.

    ReplyDelete
  11. the correct program is this without any error:-

    #include
    #include
    int main(){
    char str[20];
    int i;
    printf("Enter any string->");
    scanf("%s",&str);
    printf("The string is->%s",str);
    for(i=0;i<=strlen(str);i++){
    if(str[i]>=65&&str[i]<=90)
    str[i]=str[i]+32;
    }
    printf("\nThe string in uppercase is->%s",str);
    return 0;
    }

    ReplyDelete
  12. dont we have to use fflush(stdin) when we accept string????

    ReplyDelete
  13. inside the scnaf & then . it also not work.
    pls check it again.

    ReplyDelete
  14. create a function to change the case of alphebet

    ReplyDelete
  15. create a function to find factorial of anumber

    ReplyDelete
  16. create a function to the area of a triangle

    ReplyDelete
  17. Guys, It will just convert from Upper case to lower case !!! everything works perfectly

    ReplyDelete
  18. Hope you don't mind, but I added to the program to do both upper and lower case.

    #include

    int main(void){
    char str[20];//intitializes string
    int i = 0;

    printf("Enter any letter");//asks for a letter

    scanf("%s",&str);//scans for a letter

    for(i=0;i<=20;i++)//for loop that continues to the last character of the string
    {
    if(str[i]>=65&&str[i]<=90)//if uppercase
    str[i]=str[i]+32;//adds to character to change lower case

    else if(str[i]>=97&&str[i]<+122)//if lowercase
    str[i]=str[i]-32;//subtracts to change to uppercase
    }
    printf("\nThe opposite letter is->%s\n",str);//outputs the opposite letter
    return (0);
    }

    ReplyDelete
  19. no problem in the code.
    The statement in the final printf() should be "\nThe converted string in lower case is %s" so that the logic is correct :)

    ReplyDelete
  20. thanks boss i want this program only it works perfectly

    ReplyDelete
  21. What is the output of:
    main()
    {
    printf(5+"Good Morning");
    }

    ReplyDelete
  22. if we do string concatenation using + operator then both operands of + operator should be a string . so it make a whole string because here 5 which is an integer has been converted into string

    ReplyDelete

Share It