Program on c++

                              Programs on C++


Program to input characters and change their case (From uppercase to lowercase or vice-versa).

# include<iostream.h>

#include<stdio.h>

int main()

{

char ch;

do

{

cout<<"Enter a character:";

ch=getchar();

if(ch=='\n')

ch=getchar();

cout<<endl;

if(ch>=65&&ch<=90)

ch=ch+32;

else

if(ch>=97&&ch<=122)

ch=ch-32;

putchar(ch);

cout<<endl;

}

while(ch!='0');

return 0;

}


Output:

Enter a character : R

      r

Enter a character : a

     A

Enter a character : 0

    0


Program to read a string and print its length.

#include<stdio.h>

#include<string.h>

#include<iostream.h>

int main()

{

char astr[51];

int lenght;

cout<<"\nEnter a string (max 50characters)\n";

gets(astr);

length=strlen(astr);

puts(astr);

cout<<"\nThe lenght of the string is:"<<length<<"\n";

return 0;

}


Output:

Enter a string ( max 50 characters)

Computers

Computers

The length of the string is : 9


Program to count number of characters entered.

#include<iostream.h>

int main ()

{

int chcount=0;

const char ent='\n';

char ch;

cout<<"Enter character\n";

cin.get(ch);

while(ch!=ent)

{

chcount++;

cout.put(ch);

cin.get(ch);

}

cout<<"\nThe number of characters="<<chcount<<"\n";

return 0;

}


Output:

Enter character

Computer programming

Computer programming

The number of characters = 20



                                                                    ðŸ‘‰ IF

                                         YOU ARE

                                        WAITING 

                                         FOR THE 

                                       RIGHT TIME

                                             IT'S

                                          NOW👈

                                  

                                                                           











Comments

Popular posts from this blog

Introduction of C Language

First in C programming

Computer generation