首页 > 编程知识 正文

编写一个c语言程序输入上网时间,c语言根据每个月上网时间计算上网费用

时间:2024-04-24 11:42:59 阅读:333467 作者:VGRR

本文目录一览:

编写一个c程序,要求用户输入24小时制的时间,然后显示12小时制的格式。 例: 输入:21:11 输出: 9:11PM

#include "stdafx.h"

#include"iostream"

#include stdio.h

#include stdlib.h

#include "math.h"

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

char s[10];

scanf("%s",s);

int h,m,flag=0;

h=(s[0]-48)*10+s[1]-48;

if(h12)

{

h=h-12;

flag=1;

}

couth":"s[3]s[4];

if(flag==0)

cout"AM"endl;

else

cout"PM"endl;

return 0;

}

编写一个简单的C语言程序,在屏幕上显示一行时间(包含小时、分钟和秒钟)的信息?

#include stdio.h

#include time.h

#include stdlib.h

#include string.h

int main()

{

time_t timep,Tim;

struct tm *p;

time(timep);

p = localtime(timep); //此函数获得的tm结构体的时间,是已经进行过时区转化为本地时间

//p = gmtime(timep); //把日期和时间转换为格林威治(GMT)时间的函数

int Year = 1900 + p-tm_year;

int Month = 1 + p-tm_mon;

int Day = p-tm_mday;

int Hour = p-tm_hour;

int Minute = p-tm_min;

int Second = p-tm_sec;

char year[20];

char month[20];

char day[20];

char hour[20];

char minute[20];

char second[20];

printf("hour=%dn", Hour);

printf("minute=%dn", Minute);

printf("second=%dn", Second);

return 0;

}

每编译一次就会显示这一刻的系统时间;这个程序我也不太懂,我学长讲了半天,数据结构都整出来了,也没把我整明白,我再研究研究;希望能帮到你吧;

对C语言的一些疑问

你太强了,第一题已解决的问题里面有,自己看,第2题加/0是表示结束。第3题算术右移时2进制混合运算时候出现的。左移也有。第4题类型说明符是之指定义的类型,像int。第5题1101在2进制里面就是13=1*2的3次方+1*2的2次方+0*2的一次方+1*2的零次方。前面那么多0是机器代码,没有数据则补0,要达到机器的位数,你这个是16位的。

C语言编辑程序控制上网时间怎么写

struct pcb

{

char name;

int time;

};

void main()

{

int n,i,j,flag=1;

struct pcb a[100];

printf("输入程序个数:");

scanf("%d",n);

getchar();/*接收回车*/

for(i=0;in;i++)

{

printf("输入程序的名字:如A B C...n");

scanf("%c",a[i].name);

getchar();/*接收回车*/

printf("输入占用的时间片:");

scanf("%d",a[i].time);

getchar();/*接收回车*/

}

i=0;

while(flag n0)

{

if(a[i].time!=0)

{

printf("%c",a[i].name);

a[i].time--;

}

for(j=0;jn;j++)

if(a[j].time)

{

flag=1;

break;

}

else

flag=0;

i=(++i)%n;

}

}

另外,虚机团上产品团购,超级便宜

求助!!C++ 输入上网时间 计算上网费用

 else if(h75) //这一行少了一个if,然后错误会报在下一行。因为你在else 后面还需要添加条件,就应该用else if

  cout"费用为150元"endl;

不过我更推荐把代码改成下面这样子,会更符合题意,因为h75里的75是人脑计算出来的。你可以参考一下。

#include "iostream"

using namespace std;

void main()

{

double x;

double h;

cout"输入h"endl;

cinh;

if(h10)

cout"费用为30元"endl;

else if(h=10h50)

{

x=2.5*h;

cout"费用为"x"元"endl;

}

if (h=50)

{

x=2*h;

if(x 150)

{

cout"费用为"x"元"endl;

}

else

{

cout"费用为150元"endl;

}

}

}

C语言编程应用题

第一题#includestdio.h

void main()

{

int a,b;

printf("每月打电话的次数");

scanf("%d",a);

if(a30)

{

b=(a-30)*1;

}

else

b=0;

printf("这个月需付话费%d元",b);

} 第二题:#includestdio.h

void main()

{

int a,b,c;

printf("输入上网上时间");

scanf("%d",a);

if(a60)

{

c=8;

}

else

c=4;

b=(a/10)*1+a*c;

printf("这个月需付费用%d元",b);

}

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。