Showing posts with label Upper Case. Show all posts
Showing posts with label Upper Case. Show all posts

How To Write a C program that reads your first and last names and then converts them to upper-case and lower-case letters. The results will be printed to standard output console.

Write a C program that reads your first and last names and then converts them to upper-case and lower-case letters. The results will be printed to standard output console.



  1. //Write a C program that reads your first and last names and then converts them to upper-case and lower-case letters. The results will be printed to standard output console.
  2. #include<string.h>
  3. #include<iostream>
  4. using namespace std;
  5. int main()
  6. {
  7.     char c1[20],c2[20];
  8.     int i;
  9.     cin>>c1;
  10.     cin>>c2;
  11.     for(i=0;i<strlen(c1);i++)
  12.         if(c1[i]>='a'&&c1[i]<='z')
  13.             c1[i]=c1[i]-32;
  14.         else
  15.             if(c1[i]>='A'&&c1[i]<='Z')
  16.                 c1[i]=c1[i]+32;
  17.     for(i=0;i<strlen(c2);i++)
  18.         if(c2[i]>='a'&&c2[i]<='z')
  19.             c2[i]=c2[i]-32;
  20.         else
  21.             if(c2[i]>='A'&&c2[i]<='Z')
  22.                 c2[i]=c2[i]+32;
  23.         cout<<c1<<" "<<c2;
  24. }

C Program To Print Text Into Uppercase

How to write a C Program to print text into uppercase in C Programming Language ?

Program to Print text into Upper casing until interrupted using CTRL + Z, Program to Final Maximum of Numbers Entered until interrupted by CTRL + Z, Program to Count No of Characters until Interrupted by CTRL + Z

Program to Print text into Upper casing until interrupted using CTRL + Z

Solution For C Program :
#include<stdio.h>
void main()
{
char ch;
printf("\nPlease Enter the Data. To Stop Press CTRL+Z.\n\n");
while((scanf("%c", &ch)) > 0)
if(ch >= 'a' && ch <= 'z')
printf("%c", ch - 'a' + 'A');
else
printf("%c", ch);
}

Program to Final Maxuimum of Numbes Entered until interrupted by CTRL + Z

Solution For C Program :
#include<stdio.h>
void main()
{
int n,max=0;
printf("/nEnter the Numbers : \n\n");
while((scanf("%d", &n)) > 0)
{
printf("\nThe Given Number is : %d.\t", n);
if(max < n)
max = n;
printf("The Maximum at Present is : %d\n", max);
}
}

Program to Count No of Characters until Interrupted by CTRL + Z

Solution For C Program:

#include<stdio.h>
void main()
{
int no_chars = 0;
while(getchar() != EOF)
++no_chars;
printf("\nThe Number of Characters Entered are : %d.", no_chars);
}

You may also learn these C Program/Code :

C Program To Swap Two Numbers Without Using Third Variable

Lower-Upper Case/Positive-Negative Integer

How to let C Program to recognize both lower and upper case input. Also Check if input is a positive integer, negative integer in C Programming Language ?


This C Program is to recognize both lower and upper case input. Also Check if input is a positive integer, negative integer in C Programming Language.

Output:

  1. Your input is positive even digit
  2. Your input is negative odd digit
  3. Your input is upper case letter
  4. Your input is lower case letter

Solution :

  1. #include<stdio.h>
  2. #include<string.h>
  3. void main()
  4. {
  5.     char array[20];
  6.     int i;
  7.   for(i=0;i<5;i++){
  8.     gets(array);
  9.   if(strlen(array)==1){
  10.   if(array[i]>=48 && array[i]<=57){
  11.     if(array[i]%2==0)
  12.      printf("Your input is positive even digit\n");
  13.     else
  14.      printf("Your input is negative odd digit\n");
  15.   }
  16.   if(array[i]>=65 && array[i]<=90)
  17.     printf("Your input is upper case letter\n");
  18.   else if(array[i]>=97 && array[i]<=122)
  19.     printf("Your input is lowercase letter\n");
  20.   }
  21.   }
  22. }

C Program to convert a string to upper case

How to write a C Program to convert a string to upper case in C Programming Language ?

This C Program to convert a string to upper case.

Solution:


  1. #include<stdio.h>
  2. #include<string.h>
  3. main()
  4. {
  5.         char s[50];
  6.         int i,l;
  7.         printf("Enter some text: ");
  8.         gets(s);
  9.         l=strlen(s);
  10.         for(i=0;i<l;i++)
  11.         {
  12.                 if(s[i]>='a'&&s[i]<='z')
  13.                         s[i]-=32;
  14.         }
  15.         printf("Text after converting to upper case: ");
  16.         puts(s);
  17. }

C Program Anagrams

How to write a C Program Anagrams in C Programming Language ?

Considering a string will only contain lower-case alphabets. It can also be done for uppercase letters , digits , special characters etc.

Solution:

  1. #include<stdio.h>
  2. #include<stdbool.h>
  3. #include<string.h>
  4. bool isAnagram(char *str1,char *str2)
  5. {
  6.     int alphabetCount[26] = {0};
  7.     int i = 0;
  8.    
  9.     if(strlen(str1) != strlen(str2))
  10.         return false;
  11.    
  12.     for(i=0;str1[i]!='\0';++i)
  13.     {
  14.         ++alphabetCount[str1[i]-'a'];
  15.         --alphabetCount[str2[i]-'a'];
  16.     }
  17.    
  18.     for(i=0;i<26;++i)
  19.     {
  20.         if(alphabetCount[i])
  21.             return false;
  22.     }
  23.    
  24.     return true;
  25. }
  26.  
  27. int main(void)
  28. {
  29.    char string1[1001],string2[1001];
  30.    
  31.    /*
  32.      considering a string will only contain lower-case alphabets
  33.     It can also be done for uppercase letters , digits , special characters etc.
  34.     */
  35.    
  36.    gets(string1);
  37.    gets(string2);
  38.    
  39.    if(isAnagram(string1,string2))
  40.        printf("yes");
  41.    else
  42.        printf("no");
  43.    
  44.     return 0;
  45. }