‘壹’ VC++面向对象编程
char *str="";
enum { SUN, MON, TUE, WED, THU, FRI, SAT } weekday;
puts("请岁肆输入0-6的整数:");
scanf("%d", &weekday );
switch( weekday )
{
case SUN:
str="Sunday";break;
case MON:
str="Monday";break;
case TUE:
str="Tuesday";break;
case WED:
str="Wednesday";break;
case THU:
str="Thursday";break;
case FRI:
str="Friday";break;
default:
str="saturday";
}
printf("%s", str );
float a=0, b=0, c=0;
puts("请输入二元一次方程的系数禅雀薯:");
scanf( "%f%f%f", &a, &b, &c );
getchar();
float delta = b*b-4*a*c;
if ( delta<0 )
{
puts( "there aren't any real root." );
}
else if ( delta == 0 )
{
printf( "there's one real root:%f", -b/a/2 );
}
else
{
printf( "there're two real roots: %f and %f.", (delta-b)/a/贺者2, ( -delta-b )/a/2 );
}
‘贰’ 星期在编程中用什么来表示
PHP 写法:
获取指唤老定日期是:
$weekarray=array("日","一腔链并","二","三伍迹","四","五","六");
echo "星期".$weekarray[date("w",strtotime("2020-4-9"))];
‘叁’ C语言编程题:从键盘上输入星期号,并显示该星期的英文名称
很简单的,定义一个常量字符数组棚烂即可
#include<stdio.h>
intmain(){
intn;
char烂穗a[7][10]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
scanf("%d",&n);
饥和卜puts(a[n-1]);
return0;
}
‘肆’ C,跪求,编程,用每周的英文名称初始化一个字符指针数组,当键盘输入整数为1到7时,显示相应的周几,
#include<stdio.h>
void main()
{
char *day[]={"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};/*这是个尘巧指针数组,其中每一个元素都相当于一段兄败个指针变量,指向字符串的首字母,这种用法很常用,记下来*/
int a=0;
printf("输入1-7之间的一个数:");
scanf("%d",&a);
if(a>0&&a<握颤8)
printf("%s\n",*(day+a-1));
else printf("输入数字不在1-7之间\n");
}
‘伍’ C语言编程输入数字1到7 分别输出周一到周日的英文单词
//这个就不用戚清注释了吧
#include
"stdio.h"
void
main()
{
int
i;
printf("输入1~7其中一个数字:");
scanf("%d",&i);
switch(i)
{
case
1:
printf("Monday\n");break;
case
2:
printf("袜罩Tuesday\n");break;
case
3:
printf("Wednesday\n");break;
case
4:
printf("Thursday\n");break;
case
5:
printf("Friday\n");break;
case
6:
printf("Saturday\n");break;
case
7:
printf("Sunday\n");break;
default:
printf("April
Fools'
Day\n"告仔闹);break;
}
}
‘陆’ C语言编程题:从键盘上输入星期号,并显示该星期的英文名称
int a;
scanf("%d",&a);
swith(a)
case 1: printf("Monday");
case 2: printf("Tuseday");
case 3: printf("Wenesday");
case 4: printf("Thursday");
case 5: printf("迅敬亩Friday"稿配);
case 6: printf("Saturday");
case 7: printf("Sunday"亩森);
‘柒’ 编程问题 1 星期日 2 星期一 4 星期二 8 星期三 16 星期四 32 星期五 64 星期六 为什么要这样对应
其实很简单,这样对应的好处就是:可以用一个字节中的握和‘位’表示星期,并可以包含顷皮脊多个日子。即:
星期日:0000 0001
星期一:0000 0010
...
星期六:0100 0000
如此一来的话,你举出来的例子127,用一个字节表示就是:
0111 1111
就表示包含了星期日到星期六了。你以后判断的雀渗话,只要进行位操作即可。