3 Amazing and Simple C ++ Programs for Beginners

3 Amazing and Simple C ++ Programs for Beginners

     - IDE Used: - CodeBlocks

     - IDE = Integrated development environment

     - // = single line comments

1]  Program to swap letters of a word: -


cool c++ program for beginners
techeeINDIA




#include<iostream>
using namespace std;
void secret(char str[])
{int L,C;;
    for ( L=0;str[L]!='\0';L++);
    for ( C=0;C<L/2;C++)
        if(str[C]=='A'|| str[C]=='E')
        str[C]=str[L-C-1];
    else
    {
        char temp =str[C];
        str[C]=str[L-C-1];
        str[L-C-1]=temp;
    }
}
int main()
{
     char message[]="PreboardExam";
     secret(message);
     cout<<message<<endl;
     return 0;
}


OUTPUT: -


output c++ program
techeeINDIA

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

upper case = capital letter (  M,T,K,U)

Lower case = small letter (m,t,k,u)

Program to input characters and change their case
techeeINDIA


#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    char ch;
    do
    {
        cout<<"\nenter a character : ";
        ch=getchar();                                              //input character
        if(ch=='\n')
            ch=getchar();
        cout<<endl;
        if(ch>=65&&ch<=90)                               //if uppercase
            ch=ch+32;                                             //converted to lowercase
        else
            if(ch>=97&&ch<=122)                       //if lowercase
            ch=ch-32;                                            //converted to uppercase
        putchar(ch);
        cout<<endl;

    }while(ch!='0');
    return 0;
}


OUTPUT: -


output of Program to input characters and change their case
techeeINDIA





3] Program to read a string and print its length : -



Program to read a string and print its length
techeeINDIA





#include<iostream>                                                          //for cin,cout,  <<,   >>
#include<stdio.h>                                                            //for gets() and puts()
#include<string.h>                                                          //for strlen()
using namespace std;
int main()
{
    char astr[51];
    int length ;
    cout<<"\nenter a string(max 50 characters) : ";
    gets(astr);
    length=strlen(astr);
    puts(astr);
    cout<<"\nthe length of the string is : "<<length;
    return 0;
}



Output : -


techeeINDIA
techeeINDIA

                                                                                    - JAI HIND







3 Amazing and Simple C ++ Programs for Beginners

3 Amazing and Simple C ++ Programs for Beginners 3 Amazing and Simple C ++ Programs for Beginners Reviewed by mushrafkhan772 on June 23, 2018 Rating: 5

2 comments:

Powered by Blogger.