当前位置:首页 » 编程语言 » 如何利用c语言制作小程序
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

如何利用c语言制作小程序

发布时间: 2023-04-05 12:12:14

1. c语言编写一个小程序

#include<stdio.h>
#include<time.h>
intmain()
{
inta,b;
srand(time(NULL));
a=rand();
scanf("%d",&b);
a==b?printf("true"):printf("false");
return0;
}

//运行示例:

2. 想用c语言设计一个简单小程序,求代码。

#include<stdio.h>
int main()
{
float hour;
printf("How many hours did you excise?\nPlease input it ^_^ :");
scanf("%f",&hour); //输入函数中“”内不能加\n;
bool a,b;
a=hour>=0.5;
b=hour<=1;
if(a&&b)//判断时候,因为a和b本身就是Bool型,直接用自身就行
printf("Congratulations!You've had a perfect day!\n");
else if(a&&!b)
printf("You are too tired!please have a rest!\n");
else if(!a)
printf("You did not finish your excise,please keep doing it!\n");
return 0;
}

补充的问题在具体点

3. 如何用C语言编写一个可以自动运行某些程序的小程序

#include<windows.h>

#include<stdio.h>

#pragma comment(linker,"/subsystem:"Windows"世蚂 /entry:"mainCRTStartup"")

void main()

{

system("title 源世界整理");

int x,y;

while(1)

{x=rand()%801;

y=rand()%601;

SetCursorPos(x,y);

}

return ;

}

(3)如何利用c语言制作小程序扩展阅读

C语言猜数字的小游戏

#include <stdio.h>

#include <stdlib.h>

#include <time.h> //时间头文件。

void main()

{

int n;

int number;

srand((unsigned)time(NULL)); //产生随机数。

number=rand()%100;

printf("游戏开始乎返闭! ");

while(1)

{

printf("请输入1—100之间的整数:");

scanf("%d"岁裂,&n);

if(n==number)

{

printf("恭喜你猜对了,游戏结束。 ");break;

}

if(n>number)

printf("大了! ");

if(n<number)

printf("小了! ");

}

}

4. 用c语言做一个小程序exe

首先根据windows平台用c开发出这样的程序(这个就是我们在vc编译软件中每次编译运行出现exe窗口的部分),包括界面,内部运算什么的,这时候你要双击你c文件工程文件中debug文件夹里的exe文件就可以出现窗口,当然此时要运行的电脑必须装有类似vc++编译软件,而复制也必须复制整个工程文件夹。你的意思估计是不用整个文件夹,而是一个exe文件就可以复制运行,那样需要用打包封装软件,类似InstallShield给封装成一个exe文件,此时就不要各种.cpp .h .opt 文件了。

5. 用c语言编写小程序

/*我用c++做一下,你可以把输入输出自己转化一下*/

#include<iostream.h>

#defineMaxSize100

intdata[MaxSize][MaxSize];

voidfunc(charstr[],intn)//str是字符串,n是串长度

{

inti,j;

i=0;

for(i=0;i<n;i++)

{

j=0;

while(str[j]!='')

{

data[i][j]=(int)(str[(j+i)%n]-0x30);

j++;

}

}

}

voidmain()

{

charstr[]="123";

/*也可以自己输入串并检测串长度,这只是个测试程序*/

intn=3;

func(str,3);

for(inti=0;i<n;i++)

{

intj=0;

while(j!=n)

{

cout<<data[i][j]<<'';

j++;

}

cout<<endl;

}

}

6. 用c语言写小程序

#include <iostream>

using namespace std;

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

{

int a;

cout<<"请输入数字"<<endl;

cin>>a;

int b=0;

while(a)

{

b=a%10+10*b;

a=a/10;

}

cout<<b<<endl;

system("pause");

return 0;

}

7. 用C语言编写一个简单的图书管理小程序

源代码如下:

#include<iostream>

#include<iomanip>

#include<string>

#include<fstream>

#include<stdio.h>

using namespace std;

const int maxb=10000; //最多毁好的图书

class book//图书类

{

int tag; //删除标记1:已删0:未删

int number; //isbn书号链腊

char name[20]; //书名

char author[10]; //主编

char number2[10];//版次

char position[20];//出版社

char time[20];//出版年

void addbook(int n,char *na,char *au,char *n2,char *da,char *ti,int pr) //增加图书
{

tag=0;

number=n;

price=pr;

strcpy(name,na);

strcpy(author,au);

strcpy(number2,n2);

strcpy(position,da);

strcpy(time,ti);

onshelf=1;

}

(7)如何利用c语言制作小程序扩展阅读

1、源程序中,很多符号都是成对匹配出现棚余滑的,为避免遗漏必须配对使用的符号。

2、用花括号括起来的部分,但从程序结构清晰,便于阅读、理解、维护的角度出发,建议在书写程序时应遵循以下规则,以养成良好的编程习惯。

3、一个说明或一条语句占一行,与该结构开始处的左花括号对齐。

8. C语言编写个小程序

#include<stdio.h>
#definePi3.1416
intmain()
{floatr,h,c,s1,s2,v1,v2;
printf("请输入圆半径和圆柱高:");
scanf("%f%f",&r,&h);
c=2*Pi*r;
s1=0.5*c*r;
s2=4*s1;
v1=3*s1*r/4;
v2=s1*h;
printf("圆周长=%f 圆面积=%f 圆球表面积=%f ",c,s1,s2);
printf("圆球体积=%f 圆柱体积=%f ",v1,v2);
return0;
}

9. 用C语言写一个小程序,麻烦大家了

//记得多给点分哦,很难写的。
//C
#include<stdio.h>
intstrnmerge(char*str,intn,charconst*s1,charconst*s2){
while(n>0){
if(!(*s1)&&!(*s2))break;
if(*s1&&n>0){
*str++=*s1++;
--n;
}
if(*s2&&n>0){
*str++=*s2++;
--n;
}
}
*str='';
}
intmain(){
chars1[]="aaaa";
chars2[]="bbbbbbbbb";
charstr[100];
strnmerge(str,10,s1,s2);
printf("s1=%s ",s1);
printf("s2=%s ",s2);
printf("str=%s ",str);
return0;
}

//C++
#include<iostream>
usingnamespacestd;
intstrnmerge(char*str,intn,charconst*s1,charconst*s2){
while(n>0){
if(!(*s1)&&!(*s2))break;
if(*s1&&n>0){
*str++=*s1++;
--n;
}
if(*s2&&n>0){
*str++=*s2++;
--n;
}
}
*str='';
}
intmain(){
chars1[]="aaaa";
chars2[]="bbbbbbbbb";
charstr[100];
strnmerge(str,10,s1,s2);
cout<<"s1="<<s1<<endl;
cout<<"s2="<<s2<<endl;
cout<<"str="<<str<<endl;
return0;
}

10. C语言编写程序

代码如下:

#include<stdio.h>

intmain(void)

{

printf("Hello,world!");

return0;

}

一、首先,打开我们的Visual C++ 6.0软件,我使用的为中文版,软件主界面如下图所示:

(10)如何利用c语言制作小程序扩展阅读:

C语言的基本构成:

1、数据类型。C的数据类型包括:整型、字符型、实型或浮点型(单精度和双精度)、枚举类型、数组类型、结构体类型、共用体类型、指针类型和空类型。

2、常量与变量。常量其值不可改变,符号常量名通常用大写。变量是以某标识符为名字,其值可以改变的量。标识符是以字母或下划线开头的一串由字母、数字或下划线构成的序列,请注意第一个字符必须为字母或下划线,否则为不合法的变量名。变量在编译时为其分配相应存储单元。

3、数组。如果一个变量名后面跟着一个有数字的中括号,这个声明就是数组声明。字符串也是一种数组。它们以ASCII的NULL作为数组的结束。要特别注意的是,方括内的索引值是从0算起的。