Cプログラミング
 Computer >> コンピューター >  >> プログラミング >> Cプログラミング

Cプログラムを使用して、母音を上から下、または下から上に変換します


文字の配列は文字列と呼ばれます。

宣言

以下は配列の宣言です-

char stringname [size];

例-chara[50];長さ50文字の文字列

初期化

  • 単一文字定数の使用-
char a[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}
  • 文字列定数の使用-
char a[10] = "Hello":;

アクセス

「\0」に遭遇するまで文字列にアクセスするために使用される制御文字列「%s」があります。

母音を上から下に、または下から上に変換するために使用されるロジック は-

for(i=0;string[i]!='\0';i++){
   if(string[i]=='a'||string[i]=='e'||string[i]=='i'||string[i]=='o'||string[i]=='u'){
      string[i]=toupper(string[i]);
   }
}
printf("The result string with converted vowels is : ");
puts(string);

プログラム

以下は、変換関数を使用して大文字の文字列を小文字の文字列に変換するCプログラムです-

#include<stdio.h>
#include<ctype.h>
void main(){
   //Declaring variable for For loop (to read each position of alphabet) and string//
   int i;
   char string[40];
   //Reading string//
   printf("Enter the string : ");
   gets(string);
   //For loop to read each alphabet//
   for(i=0;string[i]!='\0';i++){
      if(string[i]=='a'||string[i]=='e'||string[i]=='i'||string[i]=='o'||string[i]=='u'){
         string[i]=toupper(string[i]);
      }
   }
   printf("The result string with converted vowels is : ");
   puts(string);
}

出力

上記のプログラムを実行すると、次の結果が得られます-

Run 1:
Enter the string : TutoRialsPoint
The result string with converted vowels is : TUtORIAlsPOInt
Run 2:
Enter the string : c programming
The result string with converted vowels is : c programming

  1. Pythonプログラムに組み込まれている関数を使用せずに、大文字と小文字をカウントします

    この記事では、以下に示す問題ステートメントの解決策について学習します。 問題の説明 −文字列が与えられたので、組み込み関数を使用せずに、文字列に存在する大文字と小文字の数を数える必要があります これは、Pythonで使用可能なislower()およびisupper()関数を使用して簡単に解決できます。ただし、ここには組み込み関数を使用するための制約があります。そこで、ここでは文字のASCII値を利用します。 ord()関数を使用して、文字列に存在する各文字のASCII値を計算し、次に示すように大文字と小文字を比較してチェックします。 例 def upperlower(string): &

  2. 指定された文字列のsetを使用して母音の数をカウントするPythonプログラム

    このプログラムでは、ユーザー入力文字列を指定します。この文字列の母音の数を数える必要があります。ここでは、Pythonでsetを使用します。 Setは、反復可能、変更可能で、重複する要素がない、順序付けされていないコレクションデータ型です。 例 Input str1=pythonprogram Output 3 アルゴリズム Step 1: first we use one counter variable which is used to count the vowels in the string. Step 2: creating a set of vowels. Step 3: the