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. }


Learn More :