四季編程
請詳細描述一下問題?
B. 有一道編程練習題,我無從下手,題目如下,判斷用戶輸入月份所屬的季節這樣的題目怎麼寫
intmonth=0;//這里表示輸入的是哪個月份
if(month>=1&&month<=3)
{
return"春季";
}
elseif(month>=4&&month<=6)
{
return"夏季";
}
elseif(month>=7&&month<=9)
{
return"秋季";
}
elseif(month>=10&&month<=12)
{
return"冬季";
}
else
{
return"月份錯誤";
}
C. Matlab編程:用for和switch語句編各月份的季節
(1)用switch語句編寫
month=input('請輸入月份(1,2,。。。,11,12)');
switch month
case 1
disp('一月份是春季')
case 2
disp('二月份是春季')
case 3
disp('三月份是春季')
case 4
disp('四月份是夏季')
case 5
disp('五月份是夏季')
case 6
disp('六月份是夏季')
case 7
disp('七月份是秋季')
case 8
disp('八月份是秋季')
case 9
disp('九月份是秋季')
case 10
disp('十月份是冬季')
case 11
disp('十一月份是冬季')
case 12
disp('十二月份是冬季')
otherwise
disp('輸入不正確')
end
D. 編寫程序:用整數1-12依次表示1-12月,由鍵盤輸入一個月份數,輸出對應的季節。
C++語言
#include<iostream>
using namespace std;
int jijie(int i){
if(i>=3&&i<=5)
cout<<"春季"<<endl;
if(i>=6&&i<=8)
cout<<"夏季"<<endl;
if(i>=9&&i<=11)
cout<<"秋季"<<endl;
if(i=12||i<=2&&i>0)
cout<<"冬季"<<endl;
return 0;
}
int main(){
int n;
cout<<"請輸入你要知道的月份:";
cin>>n;
jijie(n);
return 0;
}
E. 讓大家一個java非常簡單的編程:根據輸入1到12之間的數字,判斷是春夏秋冬哪個季節
你好,按照你的要求代碼如下,給出了注釋,可以直接運行
public class Example10_3 {
public static void main(String args[]) {
// 從1月打到12月
for (int i = 1; i <= 12; i++) {
System.out.println(getSeason(i));
}
}
// 根據月份獲得季節
private static String getSeason(int month) {
switch ((month - 1) / 3) {
case 0:
return "春";
case 1:
return "夏";
case 2:
return "秋";
case 3:
return "冬";
default:
return "錯誤";
}
}
}
F. 1.用枚舉型定義春夏秋冬四個季節,當輸入一個月份,輸出該月份對應的季節
#include <stdio.h>
enum season{Spring,Summer,Autumn,Winter};
#define Spring 0
#define Summer 1
#define Autumn 2
#define Winter 3
void main()
{
int mon;
printf("請輸入月份:");
scanf("%d",&mon);
if(mon<1 || mon > 12){
printf("你家月份里有%d月啊?",mon);
}
else{
int temp = (mon-1)/3;
switch(temp){
case Spring: printf("Spring");break;
case Summer: printf("Summer\n");break;
case Autumn: printf("Autumn\n");break;
case Winter: printf("Winter\n");break;
}
}
}
G. c#編程判斷月份所在的季節
...
這個獲取到月分,然後判斷如果在3-5月就是春季,6-8就是夏季,如果是9-11就是秋季,如果是12-2就是冬季。
H. 題設計一個一年四季(各個季節用不同的圖像表示)自動切換的程序。的VB編程代碼
Private Sub Command1_Click()
Timer1.Enabled = True
Timer1.Interval = 1000
Dim pic(3) As String
pic(0) = "C:\1.JPG" '春季
pic(1) = "C:\2.JPG" '夏季
pic(2) = "C:\3.JPG" '秋季
pic(3) = "C:\4.JPG" '冬季
End Sub
Private Sub Timer1_Timer()
If Picture1.Picture = pic(0) Then
Picture1.Picture = pic(1)
End If
If Picture1.Picture = pic(1) Then
Picture1.Picture = pic(2)
End If
If Picture1.Picture = pic(2) Then
Picture1.Picture = pic(3)
End If
If Picture1.Picture = pic(3) Then
Picture1.Picture = pic(4)
End If
If Picture1.Picture = pic(4) Then
Picture1.Picture = pic(0)
End If
End Sub
I. vfp程序設計-判斷月份的春夏秋冬
春季:3 4 5
夏季:6 7 8
秋季:9 10 11
冬季:12 1 2
而這些數有規律,把它們除以3後取整,可以得到:1 2 3 (4或0)。
clear
input "請輸入1-12的任意一個月份" to a
a=int(a/3)
do case
case a=1
?"春季"
case a=2
?"夏季"
case a=3
?"秋季"
otherwise
?"冬季"
endcase
cancel