当前位置:首页 > 黑客教程 > 正文内容

编程入门100题(经典编程100题)

hacker3年前 (2022-07-02)黑客教程188

文章大纲:

基础编程题

LZ想要的是这种答案吧。。。。

//-------------------------------之一题

#include stdio.h

#include "e:\myc\zylib\zylib.h"

STRING GetString(STRING prompt);

double GetReal(STRING prompt);

int main()

{

double bookprice;

STRING bookname;

bookname=GetString("请输入字符串:");

bookprice=GetReal("请输入实数:");

printf("字符串为:%s\n",bookname);

printf("实数为:%.2f\n",bookprice);

}

STRING GetString(STRING prompt)

{

STRING name;

printf("%s",prompt);

name=GetStringFromKeyboard();

return name;

}

double GetReal(STRING prompt)

{

double price;

printf("%s",prompt);

price=GetRealFromKeyboard();

return price;

}

//-------------------------------------第二题

#include stdio.h

#include "e:\myc\zylib\zylib.h"

BOOL IsPrime(int n);

int main()

{

int n;

printf("请输入一个整数:");

scanf("%d",n);

if(n2)

if(IsPrime(n))printf("%d是素数\n",n);

else printf("%d不是素数\n",n);

else printf("数据非法\n");

return 0;

}

BOOL IsPrime(int n)

{

int i;

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

if(n%i= =0) return FALSE;

return TRUE;

}

//--------------------------------第三题

#include stdio.h

#define TRUE 1

int gcd(int x,int y);

int main()

{

int m,n,max;

printf("请输入两个正整数:");

scanf("%d %d",m,n);

max=gcd(m,n);

printf("更大公约数为:%d\n",max);

return 0;

}

int gcd(int x,int y)

{

int r;

while(TRUE)

{

r=x%y;

if(r==0)break;

x=y;

y=r;

}

return y;

}

//--------------------------------第四题

#include stdio.h

#include "e:\myc\zylib\zylib.h"

typedef enum{sun,mon,tue,thi,wen,fri,sat}WEEKDAY;//定义枚举类型

int GetInteger(STRING prompt);//输入一下整数

int Count(int year,int month);//计算某年某月之前到2007年1月1日的天数

BOOL IsLeapYear(int n);//判断某年是否是闰年

int month_day(int year,int month);//计算某个月的天数

void print(int year,int month,int total);//打印某年某月的日历

void print1(WEEKDAY weekday);//打印某月的第1天

int main()

{

int year,month,total;

year=GetInteger("please input year:");

if(year2007)

PrintErrorMessage(FALSE,"年份小于2007,错误\n");

month=GetInteger("please input month:");

total=Count(year,month);

print(year,month,total);

}

int GetInteger(STRING prompt)

{

int t;

printf("%s",prompt);

t=GetIntegerFromKeyboard();

return t;

}

int Count(int year,int month)

{

int s,i;

s=0;

for(i=2007;iyear;i++)

if(IsLeapYear(i))s+=366;

else s+=365;

for(i=1;imonth;i++)

s+=month_day(year,i);

return s;

}

BOOL IsLeapYear(int n)

{

return n%4==0n%100!=0||n%400==0;

}

int month_day(int year,int month)

{

int day;

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 9:

case 10:

case 12:day=31;break;

case 2:day=28+IsLeapYear(year);break;

default:day=30;

}

return day;

}

void print(int year,int month,int total)

{

WEEKDAY weekday;

const WEEKDAY first=mon;

int i,day;

printf("%d-%d canlendar\n",year,month);

printf("-----------------------------------\n");

printf(" sun mon tue thi wen fri sat\n");

printf("-----------------------------------\n");

day=month_day(year,month);

for(i=1;i=day;i++)

{

weekday=(WEEKDAY)((total+i+first-1)%7);

if(i==1)print1(weekday);

else if(weekday==sat)

printf("%4d\n",i);

else printf("%4d",i);

}

printf("\n------------------------------------\n");

}

void print1(WEEKDAY weekday)

{

if(weekday==0)printf("%4d",1);

else if(weekday==1)printf("%8d",1);

else if(weekday==2)printf("%12d",1);

else if(weekday==3)printf("%16d",1);

else if(weekday==4)printf("%20d",1);

else if(weekday==5)printf("%24d",1);

else if(weekday==6)printf("%28d\n",1);

}

//---------------------------------------

上面的一些文件路径你自己改了,唉,其实我自己给你写的那些算法更好,。

JAVA基础编程题

package com.qiu.swing.layoutDemo;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.Box;

import javax.swing.BoxLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JRootPane;

import javax.swing.JTextField;

/**

*

* @author Qiu

*

*/

public class TextDemo extends JFrame{

final JButton button_show = new JButton("显示");

final JButton button_clear = new JButton("显示");

final JTextField text = new JTextField();

final Container con = this.getContentPane();

public TextDemo() {

this.setTitle("HelloWorld!");

this.setSize(300, 160);

// 居中

this.setLocationRelativeTo(null);

this.setUndecorated(true); // 去掉窗口的装饰

this.setResizable(false);

this.getRootPane().setWindowDecorationStyle(

JRootPane.INFORMATION_DIALOG);// 采用指定的窗口装饰风格

// 文字居中

text.setSize(100, 20);

Box vbox = Box.createVerticalBox();

Box xbox0 = Box.createHorizontalBox();

xbox0.add(text);

xbox0.add(button_show);

xbox0.add(button_clear);

vbox.add(xbox0);

vbox.add(Box.createVerticalStrut(100));

con.setLayout(new BoxLayout(con, BoxLayout.X_AXIS));

con.add(vbox);

button_show.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

text.setText("HelloWorld");

}

});

button_clear.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

text.setText("");

}

});

}

public static void main(String[] args) {

TextDemo home = new TextDemo();

home.setVisible(true);

}

}

1002【入门】编程求解1+2+3+...+n

#include stdio.h int main() { int i, s = 0, n; scanf("%d", n); for(i = 1; i = n; i++) s += i; printf("%d\n", s); return 0; }

扫描二维码推送至手机访问。

版权声明:本文由黑客24小时接单的网站发布,如需转载请注明出处。

本文链接:https://szlqgy.com/18186.html

“编程入门100题(经典编程100题)” 的相关文章

西安地铁4号线(西安高铁站怎么去机场)

全程约21公里从西安北站步行约400米,到二号航站楼或三号航站楼,全线还没有正式开工建设。下。现已开通火车北客站至曲江国际会展中心。 ttt3,2300西安,但是有轻轨。 方向,西安北站到咸阳机场机场城际线西安北站步行160米北客站。2012年开始建设火车北客站到西安咸阳国际机场的轻轨线路。经过2站...

女公厕现**机(公厕除臭机怎么安装)

大概5块钱一瓶……厕所是一定要勤洗的……君不见那些公共厕所天天都有人打扫吗……如,卫生管理的难度很大,将一盒清凉油打开盖放在卫生间角落低处。 臭味即可清除、从长久来使用智能除臭设备会比较方。开窗换气。 双称双极离子净,只要我们生活中随手可得的小东西,公共卫生间最好的除臭办法就是用来苏水喷洒。 我不清...

过敏性鼻炎偏方(怎样才能治好过敏性鼻炎)

治过敏性鼻炎的偏方,服用,荆芥各10克。 放几小团指甲盖大小的药棉浸葱汁备用,如果治疗不当或不及时的话会反复发作,再灌满醋至浸没蒜瓣为止。捣烂,方法是口服盐酸西替利嗪片和氯雷他定片、喷嚏打个不停,吃西药和中药当时,薄荷各6克。 边食蒜。去皮浸在一瓶陈醋、治疗时先用棉签沾淡盐。防风,预防措施很重要。所...

血红蛋白浓度(血红蛋白升高的临床意义)

病情分析。您的体检结果提示血红蛋白浓度和体积偏高。2731pg平均红。人工法平均红细胞体积。要分男女来看。血红蛋白定量测定参考值成年男性13。15克dl成年女性11。 红细胞和血红蛋白增多是什么意思。意见建议轻度正高。大面积烧伤。 平均红细胞血红蛋白浓度是一项计算出来的值,平时临床,严,以gL表示。...

德云社官网订票(德云社官网订票南京)

现在还没开票,感谢您对大麦网的支持。 演出时间2008年9月12日演出地点南京五台山体育馆售票热线025。您好亲。德云社在天桥乐的售票时间是每周六日的上午11点开始售票。 大麦网跟现场都没票,周二到周末的票都缺货,南京德云社在老门东现场买票也可以网上预定,南京郭德纲相声专场的订票方式有哪些我在外地。...

重生之鸳鸯拆散(我是被抱错的假千金)

想尽办法来排挤女,粗鄙不堪,珍惜男配”。 现代的女二是富家的抱错的养女,在阴差阳错之下重生到七八年初生的自己的体内。姝女有仙泉柔桡轻曼姝姝本是国公府嫡女,我比较喜欢看女主与男主交流的那一段。女配是重生的。 四季,定下的未婚夫婿也上门退亲,设定。黑女配。。不是什么温润如玉的公子哥。 我很讨厌霸道高冷的...

评论列表

访客
3年前 (2022-07-02)

-------------第四题#include stdio.h#include "e:\myc\zylib\zylib.h"typedef enum{sun,

访客
3年前 (2022-07-02)

tDemo() { this.setTitle("HelloWorld!"); this.setSize(300, 160); // 居中 this.setLocationRelativeTo(null); this.setUndecorated(

访客
3年前 (2022-07-02)

st=mon; int i,day; printf("%d-%d canlendar\n",year,month); printf("-----------------------------------\n"); printf(" sun mo

访客
3年前 (2022-07-02)

s = 0, n; scanf("%d", n); for(i = 1; i = n; i++) s += i; printf("%d\n", s); return 0; }

访客
3年前 (2022-07-02)

able(false); this.getRootPane().setWindowDecorationStyle( JRootPane.INFORMATION_DIALOG);// 采用指定的窗口装饰风格 // 文字居中 text.setSize(100, 20);

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。