㈠ 编程,数学题!
用编程来解决数学方面的问题必须按照一般的方法来计算,
例如1:x^2=4,这道题很容易就求解了,一般方法就是按照求根公式来解,把它看成是ax^2+bx+c=0,利用求根公式求解,期间还得先判断判别式是否为0.
例如2:1+2+……+n=?,这样的问题就得计算从头到尾的计算,不存在简便算法。
1.在编程时必须先把数值赋给一个变量,把计算结果也赋值给变量,一直变量再做计算
2.像例2是有规律的重复计算,这样的情况就要做一个循环,有循环就得有终止循环的条件。
3.初学的时候遇到基础的题型可以反复练习,看着例题的题目,自己动手编程,自己不会编就把答案记下来,离开答案再重新做一遍。
4.把例题的题目完全能够自己完成以后,再做其他的题,不求多做,只求做一道会一道,慢慢积累就好了。
㈡ 一道C语言编程题求助:计算时间差V1.0
#include<stdio.h>
intmain()
{
inth1,s1,h2,s2,h3,s3;;
printf("Inputtimeone(hour,second):");
scanf("%d,%d",&h1,&s1);
printf("Inputtimetwo(hour,second):");
scanf("%d,%d",&h2,&s2);
h3=h1-h2;
s3=s1-s2;
if(s3<0&&h3==0)s3=-s3;
elseif(h3<0)h3=-h3,s3=-s3;
if(s3<0)h3-=1,s3+=60;
printf("%dhour%dsecond ",h3,s3);
}
㈢ c#编程随机生成加减乘除的数学题目,写出答案并一分钟倒计时,结束显示答题多少,答对率多少 代码怎么写
窗体程序,加一个Timer,5个label和一个textbox,1个button
Timer的事件属性设成1000
Form_Load事件
LabelTime.Text = "60";
Timer.Start();
newWork();
-------------------
int correct = 0;
int count = 0;
void newWork(){
Random rd = new Random();
Label1.Text = rd.Next(1,100);
Label3.Text = rd.Next(1,100);
string[] fuhao = new string[]{"+","-","*","/"};
Label2.Text = fuhao[rd.Next(1,5)];
}
int getresult()
{
float result = 0;
int a = int.Parse(Label1.Text);
int b = int.Parse(Label2.Text);
switch(Label2.Text)
{
case "+":
result = a+b;
break;
case "-":
result = a-b;
break;
case "*":
result = a*b;
break;
case "/":
result = a/b
break;
}
}
-----------------------
button_Click事件
count++;
int result = int.Parse(textBox1.Text);
if(result == getresult())
{
correct ++;
}
newWork();
Timer_Tick事件
int second = int.Parse(LabelTime.Text);
if(second != 0)
{
second--;
}
else
{
textBox1.Text.Enable = false;
MessageBox.Show("共答"+count.ToString()+"题,答对"+correct.ToString()+"题,正确率"+(correct/count).ToString()+"");
Timer.Stop();
}
㈣ 如何编程实现算法时间复杂度计算
关于时间复杂度的计算是按照运算次数来进行的,比如1题:
sum1(intn)
{intp=1,sum=0,m;//1次
for(m=1;m<=n;m++)//n+1次
{p*=m;//n次
sum+=p;}//n次
return(sum);//1次
}
最后总的次数为
1+(n+1)+n+n+1+1=3n+3
所以时间复杂度f(o)=n;(时间复杂度只管n的最高次方,不管他的系数和表达式中的常量)
其余的一样,不明白的可以来问我
㈤ C语言编程题读取时间求助,谢大佬了!
字符转整形的简单应用,使用到头文件 math.h。
例如:
void TimeGet(const MYTIME *time, int *hour, int *minute, int *second)
{
*hourt = atoi(&time->hour);
*minute= atoi(&time->minute);
*second= atoi(&time->second);
}
㈥ c语言编程,怎么计算时间
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
unsigned char time1[] = {10, 8, 31, 9, 26 };
unsigned char time2[] = { 10, 8, 31, 9, 50 };
struct tm t1 = {0};
struct tm t2 = {0};
time_t _t1;
time_t _t2;
double diff;
t1.tm_year = time1[0] + 100;
t1.tm_mon = time1[1];
t1.tm_mday = time1[2];
t1.tm_hour = time1[3];
t1.tm_min = time1[4];
t2.tm_year = time2[0] + 100;
t2.tm_mon = time2[1];
t2.tm_mday = time2[2];
t2.tm_hour = time2[3];
t2.tm_min = time2[4];
_t1 = _mkgmtime( &t1 );
_t2 = _mkgmtime( &t2 );
diff = difftime(_t2, _t1 );
printf( "相差 %.0f 分钟
", diff / 60 );
}
C语言中有两个相关的函数用来计算时间差,分别是:
time_t time( time_t *t) 与 clock_t clock(void)
头文件: time.h
计算的时间单位分别为: s , ms
time_t 和 clock_t 是函数库time.h 中定义的用来保存时间的数据结构
返回值:
1、time : 返回从公元1970年1月1号的UTC时间从0时0分0秒算起到现在所经过的秒数。如果参数 t 非空指针的话,返回的时间会保存在 t 所指向的内存。
2、clock:返回从“开启这个程序进程”到“程序中调用clock()函数”时之间的CPU时钟计时单元(clock tick)数。 1单元 = 1 ms。
所以我们可以根据具体情况需求,判断采用哪一个函数。
具体用法如下例子:
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
time_t c_start, t_start, c_end, t_end;
c_start = clock(); //!< 单位为ms
t_start = time(NULL); //!< 单位为s
system("pause");
c_end = clock();
t_end = time(NULL);
//!<difftime(time_t, time_t)返回两个time_t变量间的时间间隔,即时间差
printf("The pause used %f ms by clock() ",difftime(c_end,c_start));
printf("The pause used %f s by time() ",difftime(t_end,t_start));
system("pause");
return 0;
}
因此,要计算某一函数块的占用时间时,只需要在执行该函数块之前和执行完该函数块之后调用同一个时间计算函数。再调用函数difftime()计算两者的差,即可得到耗费时间。
㈦ 一道简单的C++编程题 (1)把输入的时间数字变成时间,小时分钟秒,比如说输入(3,58,40)输出3:58:40
很简单,用string.h库里面的strstr函数即可完成任务。
㈧ 编程计算并输出两个时间(如4时55分和1时25分)之间的间隔。要求不输出时间差的负号。
#include<stdio.h>
#include<stdlib.h>
main()
{
inthour1,hour2,minute1,minute2,h,m;
printf("Inputtimeone(hour,minute):");
scanf("%d,%d",&hour1,&minute1);
getchar();
printf("Inputtimetwo(hour,minute):");
scanf("%d,%d",&hour2,&minute2);
if(hour1>hour2){
h=hour1-hour2;
if(minute1>minute2)
m=minute1-minute2;
else{
m=60+minute1-minute2;
h--;
}
}
else{
h=hour2-hour1;
if(minute1>minute2){
m=60+minute2-minute1;
h--;
}
else
m=minute2-minute1;
}
printf("%dhour%dminute ",h,m);
system("pause");
}
程序的运行结果示例1:
Inputtimeone(hour,minute):4,55↙
Inputtimetwo(hour,minute):1,25↙
3hour30minute
程序的运行结果示例2:
Inputtimeone(hour,minute):1,56↙
Inputtimetwo(hour,minute):3,25↙
1hour29minute
㈨ 数学编程高手请进一道求公式的题目
从a移动到b的总时间t=h, ......
㈩ 要易语言编程,想实现距离,时间求速度的计算。请大神帮忙。方便的话给讲讲时间的计算方式,多谢啦
无语了 , 已知 用时, 始尾点距离 算出速度 ? 这个不是很简单 .
距离以KM为单位 时间以秒为单位
距离/时间*60*60=速度(单位Km/h)