A. c语言,编程
#include<stdio.h>
main()
{
int x=1,n;
for(n=1;n<7;n++)
x=2*(x+1);
printf("总共有桃子%d个\n",x);
}
用逆向思维设计程序就行了,从第七天开始往前就OK啦
#include<stdio.h>
main()
{
int x=1,i;
printf("第7天的桃子数为:%d\n",x);
for(i=6;i>=1;i--)
{
x=2*(x+1);
printf("第%d天的桃子数为:%d\n",i,x);
}
}
这个程序就能输出每天的具体桃子数……
B. 你们在学编程的时候每天代码的练习时间是多少
每天6小时,两年就4千多小时了,有人说成为一个行业内的大师需要有1万小时的练习时间,两年下来你就是半个大师了。
C. 一个简单的C++编程
#include "time.h"
#include "stdlib.h"
#include "stdio.h"
class Time
{
public:
Time(int h , int s , int m)
{
this->h = h ;
this->s = s;
this->m = m;
}
protected:
int h,s,m;
public:
void Print()
{
printf("h = %d , s = %d , m = %d\n" , h , s , m);
}
/// 对于小时超过24的,没有增加天来保存了,就像时钟一样,25小时也就是第二天的2小时
Time operator+(Time &time1)
{
Time Tim(0,0,0);
int h = time1.h + this->h;
int s = time1.s + this->s;
int m = time1.m + this->m;
if (m > 59)
{
s += 1;
m -= 60;
}
if (s > 59)
{
h +=1;
s -= 60;
}
if (h > 23)
{
h -= 24;
}
Tim.h = h;
Tim.s = s;
Tim.m = m;
return Tim;
}
};
void main()
{
Time tim1(10,20,30) , tim2(23,50,50),tim3(0,0,0);
tim1.Print();
tim2.Print();
tim3 = tim1 + tim2;
tim3.Print();
}
D. C编程:输入年月日,计算离今天还有几天
#include<stdio.h>
int main(void)
{
int year,month,data,days;
int x=1,y=1,z=1,sum=0,a=0,b,i,j;
int a0[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int a1[12]={31,29,31,30,31,30,31,31,30,31,30,31};
printf("please input the data:\n");
scanf_s("%d%d%d",&year,&month,&data);
if ((year>9999)||(year<1990))
x=0;
if((month>12)||(month<=0))
y=0;
if((year%4==0&&year%100!=0)||year%400==0) //判断是否为闰年
{
if((data>a1[month-1])||(data<=0))
z=0;
}
else if((data>a0[month-1])||(data<=0))
z=0;
if (x&&y&&z==0)
printf("the data is illegal\n");
else
{
for (i=1990;i<year;i++)
if ((i%4==0&&i%100==0)||i%400==0)
a++;
if ((year%4==0&&year%100!=0)||year%400==0)
for (j=0;j<month;j++)
sum+=a1[j];
else
for(j=0;j<month;j++)
sum+=a0[j];
days=(year-1990)*365+sum+data+a;
printf("离今天还有%d天\n",days);
return 0;
}
E. 编程 时间换算
#include<stdio.h>
struct Time{
int hour;
int min;
int sec;
}time;//该结构体表示时间的小时数,分钟数,秒数
int main()
{
int n;
scanf("%d:%d:%d", &time.hour, &time.min, &time.sec);
scanf("%d", &n);
time.sec = time.sec + n;
if (time.sec >= 60)
{
time.min++;
time.sec =time.sec- 60;
if (time.min >= 60)
{
time.hour++;
time.min = time.min - 60;
if (time.hour >= 24)
time.hour = 0;
}
}
if (time.hour < 10)
printf("0");
printf("%d:", time.hour);
if (time.min<10)
printf("0");
printf("%d:", time.min);
if (time.sec<10)
printf("0");
printf("%d:", time.sec);
return 0;