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

日を月と日数に変換するCプログラム


ユーザーは合計日数を入力する必要があります。合計日数を月に変換し、翌月の残りの日数に変換する必要があります。

日を月に変換する式は次のとおりです-

月=日/30

次の月の残りの日を見つけるロジックは次のとおりです-

日=日%30

アルゴリズム

日を月と日数に変換するには、以下のアルゴリズムを参照してください。

Step 1: Start
Step 2: Declare month and days
Step 3: Read total number of days
Step 4: Compute months
   months=days/30
Step 5: Compute days
   Days= days % 30
Step 6: Print months
Step 7: Print days

プログラム

以下は、日数を月と日数に変換するCプログラムです-

#include<stdio.h>
main (){
   int months, days ;
   printf("Enter days\n") ;
   scanf("%d", &days) ;
   months = days / 30 ;
   days = days % 30 ;
   printf("Months = %d Days = %d", months, days) ;
}

出力

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

Enter days
456
Months = 15 Days = 6
Enter days
145
Months = 4 Days = 25

  1. Cで中実および中空の菱形パターンを印刷するプログラム

    プログラムの説明 以下に示すように、中実および中空の菱形パターンを印刷します アルゴリズム 中空菱形の場合- Accept the Number of Rows for Hollow Rhombus from the User Create a Hollow Rhombus containing the same number of Rows specified by the User. Print the first row containing the number of stars same as the number of rows. Print the second row

  2. 与えられた数を単語に変換するCプログラム

    数値で構成される文字列が与えられた場合、タスクはそれらの与えられた数値を単語で隠すことです。 入力「361​​」があるように。その場合、出力は「三百六十一」という言葉である必要があります。次の問題を解決するには、1、数万、数千などの数と場所を覚えておく必要があります。 コードは最大4桁の数字、つまり0〜9999のみをサポートします。したがって、入力は0〜9999である必要があります。 場所が-のようになるように1,111を考えてみましょう 例 Input: “1234” Output: one thousand two hundred thirty four