C_在switch
源码:
# include <stdlib.h>
# include <stdio.h>
int main()
{
int month;
int day;
printf("please input the month number: ");
scanf("%d", &month);
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day=31; // 有31天的月份情况
break;
case 4:
case 6:
case 9:
case 11: day=30; // 有30天的月份的情况
break;
case 2: day=28; // 非闰年的2月有28天
break;
default: exit(0);
}
printf("1999.%d has %d days.\n", month, day);
return 0;
}
其中,若能按输入年份分为闰年和非闰年输出每月天数,可能更好。(待解决)
相关文档:
C#从Java继承而来的特点
类:在C#中类的申明与Java很相似.这是合理的因为经验告诉我们Java模型工作得很好.Java的关键字import已经被替换成using,它起到了同样的作用.一个类开始执行的起点是静态方法Main().下面的Hello World程序展示了基本的形式:
using System;
class Hello
{
static v ......
C/C++中的Split函数是strtok()其函数原型如下:
char * strtok (char * str, const char * delimiters);
函数说明
strtok()用来将字符串分割成一个个片段。参数str指向欲分割的字符串,参数delimiters则为分割字符串,当strtok()在参数
str的字符串中发现到参数delimiters的分割字符时则会将该字符改为'\0'字符 ......
源码:
# include <stdio.h>
int main()
{
int num;
/* 下面定义的各变量,分别代表个位,十位,百位,千位,万位,十万位以及位数 */
int indiv, ten, hundred, thousand;
int ten_thousand, hundred_thous ......
源码:
# include <stdio.h>
int main()
{
int x, y, num1, num2, temp;
printf("请输入两个正整数:\n");
scanf("%d %d", &num1, &num2);
if(num1 < num2)
......
源码:
# include <stdio.h>
int main( )
{
int radius;
double area;
for(radius = 1; radius <= 10 ; radius++)
{
area = 3.1416 * radius * radius;
......