Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

C++ program to calculate the number of character in the given string

YASH PAL, 31 July 202422 August 2024

In this post, we will write a C++ program to calculate the number of characters in the given string. fist user will enter a sentence and then program will print the value of total number of letters, upper case letters, lower case latters and white space in the sentance.

C++ program to calculate the number of character in the given string

C++ program to calculate the number of character in the given string.

#include<iostream>
#include<conio.h>
#include<stdio.h>
#include<string.h>

int main()
{
   system("cls");

    char str[100];
    int i,j,n,k,o;

    i = 0;
    j = 0;
    k = 0;
    o = 0;

    puts("Enter any sentence ");
    gets(str);
    n = strlen(str);

    while(str[i] != '')
    {
        if((str[i] >= 65) && (str[i]<97))
        {
            j++;
        }
        if((str[j] >= 97) && (str[i] <= 122))
        {
            k++;
        }
        if(str[i] == ' ')
        {
            o++;
        }
        i++;
    }
    std::cout<<"The total number of letters = "<<n<<std::endl;
    std::cout<<"The upper case letters = "<<j<<std::endl;
    std::cout<<"The lower case letters = "<<k<<std::endl;
    std::cout<<"The white spaces = "<<o<<std::endl;

    getch();
    return 0;
}

Output

Enter any sentence
This program is the example of FUNCTION.
The total number of letters = 40
The upper case letters = 9
The lower case letters = 24
The white spaces = 6
C++ Programming Tutorials coding problems solutions

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes