1. Program to accept a string and print it
#include<stdio.h> #include<conio.h> // Linux user - Remove this int main() { // Declaring variable str=to store string inputted by user char str[80]; // Inputing string printf("Enter any sentence : "); gets(str); // printing string printf("\nEntered String : "); puts(str); // Another way of printing string printf("\nEnterd string : %s",str); getch(); // Linux user - Remove this return 0; }
2. Program to accept a character in the uppercase and print in lower case
#include<stdio.h> #include<conio.h> // Linux user - Remove this int main() { //Declaring variable ch to hold character value and cl=change to lower case char ch,cl; // Inputting character printf("Enter a character in uppercase : "); ch=getchar(); // Converting it to lower case cl=ch+32; // Printing lower case character printf("The given character in lowercase is : %c \n",cl); // Another way of priting printf("The given character in lowercase is : "); putchar(cl); getch(); // Linux user - Remove this return 0; }
3. Program to accept a character in Lower case and print it in upper case
# include <stdio.h> # include <conio.h> // Linux user - Remove this int main( ) { // Declaring variable ch=character, cu=change character to upper case char ch,cu; // Entering character printf("Enter a charcater in lower case: "); scanf("%c",&ch); // Converting it to upper case cu=ch-32; // Printing upper case character printf("The given character in upper case is : %c \n",cu); getch( ); // Linux user - Remove this return 0; }
4. Program to accept a character in any case and print in another case
#include<stdio.h> #include<conio.h> // Linux user - Remove this int main() { // Declaring variable ch to hold character value and cch=change character char ch,cch; // Inputting character printf("Enter a character in anycase : "); scanf("%c",&ch); // Changing case if(ch>=65 && ch<=90) cch=ch+32; else if(ch>=97 && ch<=122) cch=ch-32; // Printing Changed case printf("Changed character : %c ",cch); getch(); // Linux user - Remove this return 0; }
5. Program to accept a string and print it by using while loop
#include<stdio.h> #include<conio.h> // Linux user - Remove this int main() { // Declaring variable ch to store input character char ch; // Inputing and displaying string printf("Enter a string : "); while(( ch=getchar( ))!='\n') putchar(ch); getch(); // Linux user - Remove this return 0; }