当前位置:首页 » 编程软件 » 简单编程题

简单编程题

发布时间: 2023-04-11 14:51:56

❶ 求几道简单c语言编程题答案

1.
#include
<stdio.h>
int
main()
{
int
y0,
m0,
d0,
y1,
m1,
d1,
age;
while
(
scanf("%d%d%d%d%d%d",
&y0,
&m0,
&d0,
&y1,
&m1,
&d1
)
){
age
=
y1
-
y0
-
1;
if
(
m1
>
m0
||
m1
==
m0
&&
d1
>=
d0
)
++age;
printf("年龄为:%d周岁!\n",
age);
}
return
0;
}
4.
#include
<stdio.h>
#include
<memory.h>
int
main()
{
char
p[500];
int
i,
count;
while
(
scanf("%s",
&p)
){
count
=
0;
for
(
i
=
0;
i
!=
strlen(p);
++i
)
if
(
p[i]
>=
'a'
&&
p[i]
<=
'z'
)
++count;
printf("%d\n",
count);
}
return
0;
}
2.
#include
<stdio.h>
int
main()
{
int
n;
while
(
scanf("%d",
&n)
){
if
(
(
n
&
1
)
==
0
)
printf("%d是偶数!\n",
n);
else
printf("%d,是奇数!\n",
n);
}
return
0;
}
第三题(用EFO结束)?EOF吧?EOF已经是文件尾,怎样输出结果?

❷ 跪求大神解答两道简单的Delphi编程题,小弟拜托了,考试了!

编程题1:

procereTForm1.FormActivate(Sender:TObject);
constMAX_LINE=100;
vari:Integer;
begin
randomize();
withCanvasdo
begin
fori:=1toMAX_LINEdo
begin
巧春Pen.Color:=random(65536);
LineTo(random(ClientRect.Right-ClientRect.Left),random(ClientRect.Bottom-ClientRect.Top));
sleep(500);
Application.ProcessMessages;
end;
end;
end;

运行结果:

Withqry1do
begin
//添加记录
Append;
Fieldbyname('字段名').Value:=值;
post;

//添加记录
Edit;
Fieldbyname('字段名').Value:=值;
post;

//删除记录
DeleteRecords(arCurrent);
end;

❸ 急急急@!!!简单C语言编程题,

#include<stdio.h>
double
Rectang(double
x,double
y)
{
double
Perimet,Area;
Perimet=(x+y)*2;

//根据长和宽计算周长
Area=x*y;

//计算面积
printf("长方形缓念周长为:%g\n",Perimet);
//输出计算结果
printf("长方形面积为:%g\n",Area);
}
main()
{
float
x,y;
printf("请输入长方形的长和宽,用空格隔开!例如
4
5\n");
//显示配神提示培哪亏信息
scanf("%f
%f",&x,&y);

//输入长方形的长和宽
Rectang(x,y);

//调用自定义函数计算长方形的周长和面积
return
1;
}

❹ 很简单的C语言题目

二、填空题
1.答:7
因为
'H'(ASCII) -'桐源A'(ASCII) = 7(十进制)
7(十进制)+'0'(ASCII) = '7'(ASCII)
注:原文print错误,是printf

2.答:3
因为p/3>0,所以这个表达式返回p/10即3

3.答:b
因为'B'(ASCII) = 66(十进制),'B'+ 32 = 98(即ASCII的b)

三、编程题
1.打印的结果为9,11,9,10
因为
【m=++i;】等效于【i=i+1,m=i;】
【n=j++;】等效于【n=j,j=j+1;】

二、填空题
1要求给i赋10,给j赋20,则应该从键盘输入 i=10,j=20。
因为scanf("i=%d,j=%d",&i,&j);
同理,如果scanf("%d,%d",&i,&j); 只要输入10,20即可
注:原文scanf("i=%d,j=%d";&i,&j);语句中&i前的分号是错的,应用逗号。

2. 以下程序的输出结果是 2,1(加个换行)。
a=a+b;//a=3,b=2
b=a-b;//a=3,b=1
a=a-b;//a=2,b=1

三、编程题
1. 设圆半径r=1.5,高h=3,求局升态圆周长、圆面积、圆球表面积、圆球体积、圆柱体积。用scanf输入数据,输出计算结果,输出时要求有文字说明,取小数点后2位数字。请编程序。
答:

//圆周长:2*PI*r
//圆面积:PI*r*r
//圆球表面积:4*PI*r*r
//圆球体积:4/3*PI*r*r*r
//圆柱体积:PI*r*r*h

#include <stdio.h>
#define PI 3.14159f//定义π
float r;//半径
float h;//高
void main(void)
{
printf("请输入圆半径,以回车确认:");
scanf("%f",&r);
printf("请输入高,以回车确认:");
scanf("%f",&h);
printf("圆周长为:%.2f\n", 2*PI*r);
printf("圆面积为:%.2f\n"笑蚂, PI*r*r);
printf("圆球表面积为:%.2f\n", 4*PI*r*r);
printf("圆球体积:%.2f\n", 4/3*PI*r*r*r);
printf("圆柱体积:%.2f\n", PI*r*r*h);
}

❺ 两道简单的C语言编程题 1.设给定三个整数a.b.c,试写出寻找其中数的一个算法,并分析在平均情况

先回答第一个问题:

#include<stdio.h>
#include<conio.h>
intmain(){
inta,b,c,d;
printf("Inputa,b,c:");
scanf("%d,%d,%d",&a,&b,&c);
if(a>=b){
if(b>=c)d=b;//a>=b>=c,比较2次
elseif(a>=c)d=c;//a>=c>b,比较3次
elsed=a;//c>a>=b,比较3次
}else{
if(a>=c)d=a;//b>a>=c,比较2次
elseif(b>=c)d=c;//b>=c>a,比较3次
elsed=b;//c>b>a,比较3次
}//平均比较次数:(2+3+3+2+3+3)/6=8/3次,最坏比较次数:3次
printf("ZhongShu=%d Finished! ",d);
getch();
return0;
}

平均比较8/3次,最坏比较3次。第二个问题:

#include<stdio.h>
#include<conio.h>
intBinMax(inta[],intlow,inthigh){//二分查找最大值,low、high为查找范围下标
if(low>high){
printf(" BinMaxError! ");
return-32768;//范围出错,提示,并返回整型最小值
}
if(low==high)returna[low];
if(low==high-1)return(a[low]>a[high]?a[low]:a[high]);
intmid=(low+high)/2,m1,m2;
m1=BinMax(a,low,mid);//找前半部的最大值
m2=BinMax(a,mid+1,high);//找后半部的最大值
return(m1>m2?m1:m2);
}
intmain(){
inta[9]={3,6,2,5,9,1,8,7,10},max;//元素个数不一定要满足n=2^k
max=BinMax(a,0,8);
printf("max=%d Finished! ",max);
getch();
return0;
}

都能看懂吧?希望能帮到你!

❻ 一 个简单的编程题目

#include <iostream.h>
int A[15]={14,1,2,3,4,5,6,7,8,9,10,11,12,13,14};
/*A[1..14];为了下标从1开始,我用15个空间存14个数,第一个空间存数组长度
程序运行不结束是正确的因为14个数的全排列要1278945280个输出
*/
void Write(int a[])
{
// output the the elements of an array;
//input : an array
for(int i = 1;i<=14;i++)
cout<<a[i]<<'\t';
cout<<endl;
sum++;
}
void HeapPermute(int n)
{
/*实现生成全排列的Heap算法
输入全局数组A[1..n]
输出 A的全排列*/
if (n==1)
Write(A);
else
for(int i = 1;i<=n;i++)
{
HeapPermute(n-1);
if (n%2 != 0)
Swap(A[1],A[n]);
else
Swap(A[i],A[n]);
}
}

int main()
{
HeapPermute(14);
//cout<<fun(6);
//cout<<sum<<endl;
//cout<<SearchMin(A,1,5)<<endl;

return 0;
}

❼ C语言指针一道简单的编程题

按照你的要求编写的C语言程序如下

include<stdio.h>
intmain()
{
inta,b;
int*p=&a;
a=30;
printf("a=%d ",*p);
p=&b;
scanf("%d",p);
a=*p+24;
printf("a=%d,b=%d",a,b);
return0;
}

运行结果
a=30
76
a=100,b=76

❽ 5道简单的java编程题(高分悬赏)

很详细的帮你写下,呵呵,所以要给分哦!
1、
(1)源程序如下:
public class One {

public static void main(String[] args) {
String name = "张三";
int age = 23;
char sex = '男';
String myclass = "某某专业2班";
System.out.println("姓名:" + name);
System.out.println("姓名:" + age);
System.out.println("姓名:" + sex);
System.out.println("姓名:" + myclass);

}

}

(2)

编写完程序的后缀名是.java,如本题,文件名就是One.java。
开始\运行\cmd,进入“命令提示符窗口”,然后用javac编译器编译.java文件,语句:javac One.java。

(3)
编译成功后,生成的文件名后缀是.class,叫做字节码文件。再用java解释器来运行改程序,语句:java One

2、编写程序,输出1到100间的所有偶数
(1)for语句
public class Two1 {

public static void main(String[] args) {
for(int i=2;i<=100;i+=2)
System.out.println(i);

}
}

(2)while语句
public class Two2 {

public static void main(String[] args) {
int i = 2;
while (i <= 100) {
System.out.println(i);
i += 2;
}
}
}

(3)do…while语句
public class Two3 {

public static void main(String[] args) {
int i = 2;
do {
System.out.println(i);
i += 2;
}while(i<=100);
}
}

3、编写程序,从10个数当中找出最大值。
(1)for循环
import java.util.*;

public class Three1 {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
for (int i = 0; i < 10; i++) {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
}
System.out.println("最大值:" + max);
}
}

(2)while语句
import java.util.*;

public class Three2 {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
while (i < 10) {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
i++;
}
System.out.println("最大值:" + max);
}
}

(3)do…while语句
import java.util.*;

public class Three3 {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int number;
int max = 0;
int i = 0;
do {
System.out.print("输入第" + (i + 1) + "个数:");
number = input.nextInt();
if (max < number)
max = number;
i++;
}while(i<10);
System.out.println("最大值:" + max);
}
}

4、编写程序,计算从1到100之间的奇数之和。
(1)for循环

public class Four1 {

public static void main(String[] args) {
int sum=0;
for(int i = 1;i<=100;i+=2){
sum+=i;
}
System.out.println("1~100间奇数和:" + sum);
}
}

(2)while语句
public class Four2 {

public static void main(String[] args) {
int sum = 0;
int i = 1;
while (i <= 100) {
sum += i;
i += 2;
}
System.out.println("1~100间奇数和:" + sum);
}
}

(3)do…while语句
public class Four3 {

public static void main(String[] args) {
int sum = 0;
int i = 1;
do {
sum += i;
i += 2;
} while (i <= 100);
System.out.println("1~100间奇数和:" + sum);
}
}

5、
(1)什么是类的继承?什么是父类?什么是子类?举例说明。
继承:是面向对象软件技术当中的一个概念。如果一个类A继承自另一个类B,就把这个A称为"B的子类",而把B称为"A的父类"。继承可以使得子类具有父类的各种属性和方法,而不需要再次编写相同的代码。在令子类继承父类的同时,可以重新定义某些属性,并重写某些方法,即覆盖父类的原有属性和方法,使其获得与父类不同的功能。另外,为子类追加新的属性和方法也是常见的做法。继承需要关键字extends。举例:
class A{}
class B extends A{}
//成员我就不写了,本例中,A是父类,B是子类。

(2)编写一个继承的程序。
class Person {
public String name;
public int age;
public char sex;

public Person(String n, int a, char s) {
name = n;
age = a;
sex = s;
}

public void output1() {
System.out.println("姓名:" + name + "\n年龄:" + age + "\n性别:" + sex);
}
}

class StudentPerson extends Person {
String school, department, subject, myclass;

public StudentPerson(String sc, String d, String su, String m, String n,
int a, char s) {
super(n, a, s);
school = sc;
department = d;
subject = su;
myclass = m;
}

public void output2() {
super.output1();
System.out.println("学校:" + school + "\n系别:" + department + "\n专业:"
+ subject + "\n班级:" + myclass);
}
}

public class Five2 {

public static void main(String[] args) {
StudentPerson StudentPersonDemo = new StudentPerson("某某大学", "某某系别",
" 某专业", "某某班级", " 张三", 23, '男');
StudentPersonDemo.output2();
}
}

❾ 一道简单的python编程题

按照题目要求编写的哥德巴赫猜想的Python程序如下

def IsPrime(v):

if v>=2:

for i in range(2,v//2+1):

if v%i==0:

return False

else:

return True

else:

return False

n=int(input("输入一个正偶数:"))

if n>2 and n%2==0:

for i in range(1,n//2+1):

if IsPrime(i)==True and IsPrime(n-i)==True:

print("%d=%d+%d" %(n,i,n-i))

else:

print("输入数据出错!")

源代码(注意源代码的缩进)

❿ 初学者请教 两道简单的c语言编程题目

[回答]
1. 用C语顷春言自己的时间函数
difftime(time_t time1, time_t time0) / 86400
这样做得缺点是,这里的time_t类型,只支持到2037年

2. 自己定义函数
楼主用的方法,在实际编程里不常用,变化比较大。
下面这个方法是直接计算两个日期到公元元年的天数
然后相减,这个是实际编程时的算法,经过很多程序员的洗炼,已经被广泛使用

#include<stdio.h>
#define LEAP(y) (y%(y%100?4:400)==0) /*公元y年是否闰年*/
long totaldays(int year,int month,int day)/*公元纪年的总天数*/此汪
{ int days[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int c=day,m,y=year-1;
days[2]=28+LEAP(year);
for(m=1;m<month;m++)c+=days[m];
return c+y/4-y/100+y/400+y*365L;
}
void main()
{ int y,m,d; long t1,t2;
printf("date 1: ");
scanf("%d%*c%d%*c%d",&y,&m,&d);
t1=totaldays(y,m,d);
printf("date 2: ");
scanf("%d%*c%d%*c%d",&y,&m,&d);
t2=totaldays(y,m,d);
printf("total days: %ld\n",t2-t1);
}

这应该是全部的实现方法了
楼主的方法没必要简化了
尤其是刻意追求短代码就更没有必要了
要知道雀扒耐,代码短了,可读性就差
两者协调好,才能称为好程序^^

悉雨辰寂

热点内容
谜宫脚本 发布:2025-07-15 12:40:07 浏览:864
安卓手机语音操作在哪里开启 发布:2025-07-15 12:18:49 浏览:283
安卓导航仪上网卡插哪里 发布:2025-07-15 12:01:58 浏览:453
把文件编译成数据 发布:2025-07-15 11:53:16 浏览:542
mt4如何修改密码 发布:2025-07-15 11:53:16 浏览:215
2021思域新款买哪个配置 发布:2025-07-15 11:33:24 浏览:772
路由搭建http服务器 发布:2025-07-15 11:26:45 浏览:724
消遣解压 发布:2025-07-15 11:26:43 浏览:393
ICL编译 发布:2025-07-15 11:26:32 浏览:665
快看吧交易密码多少 发布:2025-07-15 11:26:26 浏览:483