
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Convert all lowercase characters to uppercase whose ASCII value is co-prime with k in C++
In this tutorial, we will be discussing a program to convert all lowercase characters to uppercase whose ASCII value is co-prime with k.
For this we will be provided with a string and an integer value k. Our task is to traverse through the given string and change to uppercase all those characters whose ASCII value is co-prime with the given integer k.
Example
#include <bits/stdc++.h> using namespace std; //modifying the given string void convert_string(string s, int k){ int l = s.length(); for (int i = 0; i < l; i++) { int ascii = (int)s[i]; //checking if the value is coprime with k if (ascii >= 'a' && ascii <= 'z'&& __gcd(ascii, k) == 1) { char c = s[i] - 32; s[i] = c; } } cout << s << "\n"; } int main(){ string s = "tutorialspoint"; int k = 3; convert_string(s, k); return 0; }
Output
TuToriAlSPoiNT
- Related Articles
- Golang Program to convert Uppercase to Lowercase characters, using binary operator.
- How to convert all uppercase letters in string to lowercase in Python?
- Convert All Lowercase Text of a File into Uppercase in Java?
- Convert string to lowercase or uppercase in Arduino
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k in C++
- Count characters in a string whose ASCII values are prime in C++
- How to convert all the records in a MySQL table from uppercase to lowercase?
- Replacing all special characters with their ASCII value in a string - JavaScript
- How to convert lowercase letters in string to uppercase in Python?
- Making a Java String All Uppercase or All Lowercase.
- Java program to convert a string to lowercase and uppercase.
- Check if lowercase and uppercase characters are in same order in Python
- Converting Odd and Even-indexed characters in a string to uppercase/lowercase in JavaScript?
- Convert Hex to ASCII Characters in the Linux Shell
- Write a C program to convert uppercase to lowercase letters without using string convert function

Advertisements