用C语言编写一个浪漫软件

用C语言编写一个浪漫软件,第1张

#include<iostream>

using namespace std;

void prinstar(void)

{

cout<<" 爱爱爱爱爱爱爱爱爱爱爱爱爱"<<endl;

cout<<" 爱"<<endl;

cout<<" 爱 "<<endl;

cout<<" 爱"<<endl;

cout<<" 爱"<<endl;

cout<<" 爱"<<endl;

cout<<" 爱"<<endl;

cout<<" 爱"<<endl;

cout<<" 爱爱爱爱爱爱爱爱爱爱爱爱爱爱爱爱爱爱爱"<<endl;

}

void print_message(void)

{ cout<<" "<<endl;

cout<<" "<<endl;

cout<<" "<<endl;

cout<<" "<<endl;

cout<<"爱 爱 爱 爱 爱爱爱爱爱爱"<<endl;

cout<<"爱 爱 爱 爱 爱 爱"<<endl;

cout<<"爱 爱 爱 爱 爱 爱"<<endl;

cout<<"爱 爱 爱 爱 爱 爱"<<endl;

cout<<"爱 爱 爱 爱 爱 爱爱爱爱爱爱"<<endl;

cout<<"爱 爱 爱 爱 爱 爱 "<<endl;

cout<<"爱 爱 爱 爱 爱 爱"<<endl;

cout<<"爱 爱 爱 爱 爱 爱"<<endl;

cout<<"爱爱爱爱爱 爱 爱 爱爱爱爱爱爱"<<endl;

}

void message(void)

{ cout<<" "<<endl;

cout<<" "<<endl;

cout<<" "<<endl;

cout<<" "<<endl;

cout<<" 爱 爱 爱 爱 爱"<<endl;

cout<<" 爱 爱 爱 爱 爱 爱 "<<endl;

cout<<" 爱 爱 爱 爱 爱 爱 "<<endl;

cout<<" 爱 爱 爱 爱 爱 爱 "<<endl;

cout<<" 爱 爱 爱 爱 爱 爱"<<endl;

cout<<" 爱 爱 爱 爱 爱 "<<endl;

cout<<" 爱 爱 爱 爱 爱爱"<<endl;

cout<<" 爱 爱 爱 爱 爱 爱"<<endl;

cout<<" 爱 爱 爱 爱 爱 爱"<<endl;

cout<<" 爱 爱 爱"<<endl;

}

int main(void)

{

prinstar();

print_message();

message();

return 0;

}

好像有好多运行不了,我也不知道怎么回事,毕业好多年了,现在连C语言是啥都不知道了,哎,岁月是吧杀猪刀啊

#include <stdioh>

#include <stdlibh>

#define NUM 10

/ run this program using the console pauser or add your own getch, system("pause") or input loop /

//冒泡排序算法

//基本思想:比较相邻的两个数,如果前者比后者大,则进行交换。每一轮排序结束,选出一个未排序中最大的数放到数组后面。

void bubbleSort(int arr, int n) {

int i,j;

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

for (j = 0; j < n - i - 1; j++) {

//如果前面的数比后面大,进行交换

if (arr[j] > arr[j + 1]) {

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

}

}

}

//最差时间复杂度为O(n^2),平均时间复杂度为O(n^2)。稳定性:稳定。辅助空间O(1)。

//升级版冒泡排序法:通过从低到高选出最大的数放到后面,再从高到低选出最小的数放到前面,

//如此反复,直到左边界和右边界重合。当数组中有已排序好的数时,这种排序比传统冒泡排序性能稍好。

//升级版冒泡排序算法

void bubbleSort_1(int arr, int n) {

//设置数组左右边界

int left = 0, right = n - 1;

//当左右边界未重合时,进行排序

while (left<=right) {

int i,j;

//从左到右遍历选出最大的数放到数组右边

for (i =left; i < right; i++) {

if (arr[i] > arr[i + 1]) {

int temp = arr[i];

arr[i] = arr[i + 1];

arr[i + 1] = temp;

}

}

right--;

//从右到左遍历选出最小的数放到数组左边

for (j = right; j> left; j--) {

if (arr[j + 1] < arr[j]) {

int temp = arr[j];

arr[j] = arr[j + 1];

arr[j + 1] = temp;

}

}

left++;

}

}

int main(int argc, char argv[]) {

int arr[NUM],i,j,temp;

printf("请输入10个数:\n");

for(i=0; i<NUM; i++) {

printf("请输入第(%d)个数:",i+1);

scanf("%d",&arr[i]);

}

printf("\n输入如下排列:\n");

for(i=0; i<NUM; i++) {

printf("%4d",arr[i]);

}/

for(i=0; i<NUM; i++) {

for(j=i+1; j<NUM; j++) {

if(arr[i]>arr[j]) {

temp=arr[i];

arr[i]=arr[j];

arr[j]=temp;

}

}

}/

bubbleSort_1(arr,NUM);

/printf("\n从小到大如下排列:\n");

for(i=0; i<NUM; i++) {

printf("%4d",arr[i]);

}/

printf("\n从大到小如下排列:\n");

for(i=NUM-1; i>=0; i--) {

printf("%4d",arr[i]);

}

return 0;

}

#include <stdioh>

#include <mathh>

#include <stdlibh>

#define I 20

#define R 340

#include <stringh>

int main()

{

char answer[10];

printf("遇到你\n我才发现\n曾经所有的条件\n似乎都成了我等你的借口\n\n");

printf("我对你的感情已经决堤\n所以\n请允许我,从今往后映入你\n明媚的眼\n");

printf("我\n想和你\n耳鬓厮磨,相濡以沫!");

printf("答应我吧!\n输入yes,你可以看到我的真心\n");

scanf("%s", answer);

float y, x, z, f;

for (y = 15f; y > -15f; y -= 01f)

{

for (x = -15f; x < 15f; x += 005f)

{

z = x x + y y - 1;

f = z zz - x xyyy;

putchar(f <= 00f ""[(int)(f-80f)] : ' ');

}

putchar('\n');

}

long time;

for (;;)

{

system("color a");

for (time = 0; time<99999999; time++);

system("color b");

for (time = 0; time<99999999; time++);

system("color c");

for (time = 0; time<99999999; time++);

system("color d");

for (time = 0; time<99999999; time++);

system("color e");

for (time = 0; time<99999999; time++);

system("color f");

for (time = 0; time<99999999; time++);

system("color 0");

for (time = 0; time<99999999; time++);

system("color 1");

for (time = 0; time<99999999; time++);

system("color 2");

for (time = 0; time<99999999; time++);

system("color 3");

for (time = 0; time<99999999; time++);

system("color 4");

for (time = 0; time<99999999; time++);

system("color 5");

for (time = 0; time<99999999; time++);

system("color 6");

for (time = 0; time<99999999; time++);

system("color 7");

for (time = 0; time<99999999; time++);

system("color 8");

for (time = 0; time<99999999; time++);

system("color 9");

}

getchar();

return 0;

}

运行效果:

扩展资料:

printf函数使用注意事项

1、域宽

%d:按整型数据的实际长度输出。

如果想输出指定宽度可以指定域宽,%md--&gt;m域宽,打印出来以后,在控制台上,显示m位;

如果我们要打印的数的位数如果超过我们设定m则原样输出;

如果我们要打印的数的位数如果小于我们设定的位数,则补空白,具体如下:

如果m为正数,则左对齐(左侧补空白);

如果m为负数,则右对齐(右侧补空白)。

2、转义字符

如果想输出字符"%",则应该在“格式控制”字符串中用连续两个%表示。

如:printf("%f%%",1.0/3);输出结果:0.333333%。

你需要的是编译器,比如TurboC,MSC,或者VC等等,你写的C代码只是源程序而已,需要经过C编译器编译成可执行的EXE文件。C编译器有很多,上面提到的就是比较常用的,至于编译器的使用,你得另查一查使用手册,一般而言,编译器都带有IDE的集成编程环境,可以作为程序的编辑器(别把编辑器和编译器弄混了,编辑器就是可以输入源代码的软件工具,如记事本就是一个最简单的编辑器,编译器就是用于编译特定语言源代码的软件),然后一般都有一个编译(Compile)按钮(或者编译命令),编译时编译器会检查你的源代码是否有语法错误,如果没有错误,还会使用链接(Link)工具将你的程序链接成为可执行的Exe文件,至此,你的源程序就成了可运行的程序了。运行EXE文件是不用源代码的,它与编写程序的语言无关,各种编程语言写成的源程序经过该编程语言的编译器可以被编译成在计算机上可以被运行的执行程序。

#include<stdioh>

#define N 200

struct child

{

char name[10];

char sex[3];

int age;

int height;

float weight;

struct {

int year;

int month;

int day;

}bdate;

}ch[N];

void input()

{

int i;

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

{

printf("\n请输入第%d名小朋友信息:\n",i+1);

printf("姓名:");

scanf("%s",ch[i]name);

printf("性别:");

scanf("%s",ch[i]sex);

printf("年龄:");

scanf("%d",&ch[i]age);

printf("身高:");

scanf("%d",&ch[i]height);

printf("体重:");

scanf("%f",&ch[i]weight);

printf("出生日期[YYYY-MM-DD]:");

scanf("%d-%d-%d",&ch[i]bdateyear,&ch[i]bdatemonth,&ch[i]bdateday);

}

}

void sort()

{

struct child ct;

int i,j;

for(i=0;i<N-1;i++)

for(j=0;j<N-i-1;j++)

if(ch[j]height<ch[j+1]height)

{

ct=ch[j];

ch[j]=ch[j+1];

ch[j+1]=ct;

}

}

void output()

{

int i;

printf("\n\t幼儿园小朋友一览(依身高排序)\n");

printf("===================================================\n");

printf(" 姓名 性别 年龄 身高 体重 出生日期 \n");

printf("===================================================\n");

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

printf(" %-8s %-2s %2d %d %31f %d%d%d\n",ch[i]name,ch[i]sex,ch[i]age,ch[i]height,ch[i]weight,ch[i]bdateyear,ch[i]bdatemonth,ch[i]bdateday);

}

void main()

{

input();

sort();

output();

}

//分给的忒少,呵呵

我说思路把 写太累

俩个办法

1 嵌套循环 一个循环代表列 一个循环代表行

逻辑比较复杂 但是代码量 较小

2 char [] [] 二位数组 一个一个写喽 空的 用字符串‘ ’ 实心的 ‘’ 完了循环打印

辛苦的初始化

#define IdYes 1002

#define IdNo 1003

#define IdStatic 1004

#define IdTimer 1005

#define Width 640

#define Height 480

#define Tick 2000

#include<windowsh>

int x,y;

RECT rdesk;

HINSTANCE hinst;

HWND hyes,hno;

BOOL quit=FALSE;

LRESULT CALLBACK WndProc(HWND hwnd,UINT Message,WPARAM wParam,LPARAM lParam)

{

HDC hdc;

PAINTSTRUCT ps;

RECT rclient;

HBRUSH hbrbkgnd;

static COLORREF c;

static BYTE r,g,b;

switch(Message)

{

case WM_TIMER:

if(IdTimer==LOWORD(wParam))

{

r=(BYTE)(rand()%256);

g=(BYTE)(rand()%256);

b=(BYTE)(rand()%256);

c=RGB(r,g,b);

InvalidateRect(hwnd,NULL,TRUE);

UpdateWindow(hwnd);

}

break;

case WM_PAINT:

hdc=BeginPaint(hwnd,&ps);

hbrbkgnd=CreateSolidBrush(c);

SelectObject(hdc,hbrbkgnd);

GetClientRect(hwnd,&rclient);

FillRect(hdc,&rclient,hbrbkgnd);

DeleteObject(hbrbkgnd);

EndPaint(hwnd,&ps);

break;

case WM_COMMAND:

switch(LOWORD(wParam))

{

case IdYes:

quit=TRUE;

MessageBox(hwnd,TEXT("回答正确,太太太好了!"),TEXT("宝贝"),MB_ICONEXCLAMATION|MB_OK);

SendMessage(hwnd,WM_CLOSE,0,0);

break;

case IdNo:

MessageBox(hwnd,TEXT("回答错误哦,我很生气呢!"),TEXT("宝贝"),MB_ICONEXCLAMATION|MB_OK);

break;

}

break;

case WM_SIZE:

case WM_MOVE:

SetWindowPos(hwnd,HWND_TOPMOST,x,y,Width,Height,SWP_SHOWWINDOW);

break;

case WM_DESTROY:

PostQuitMessage(0);

break;

case WM_CLOSE:

if(quit)

{

KillTimer(hwnd,IdTimer);

DestroyWindow(hwnd);

}

break;

case WM_CREATE:

CreateWindow(TEXT("Static"),

TEXT("请回答:做我女朋友好吗?"),

WS_CHILD|WS_VISIBLE|SS_CENTER,

200,

200,

240,

20,

hwnd,

(HMENU)IdStatic,

hinst,

NULL

);

hyes=CreateWindow(TEXT("Button"),

TEXT("好"),

WS_CHILD|WS_VISIBLE|BS_CENTER,

270,

230,

45,

20,

hwnd,

(HMENU)IdYes,

hinst,

NULL

);

hno=CreateWindow(TEXT("Button"),

TEXT("不好"),

WS_CHILD|WS_VISIBLE|BS_CENTER,

325,

230,

45,

20,

hwnd,

(HMENU)IdNo,

hinst,

NULL

);

SetTimer(hwnd,IdTimer,Tick,NULL);

break;

default:

return DefWindowProc(hwnd,Message,wParam,lParam);

}

return 0;

}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)

{

WNDCLASSEX wc;

HWND hwnd;

MSG msg;

hinst=hInstance;

srand(time(NULL));

memset(&wc,0,sizeof(wc));

wccbSize=sizeof(WNDCLASSEX);

wclpfnWndProc=WndProc;

wchInstance=hInstance;

wchCursor=LoadCursor(NULL,IDC_ARROW);

wchbrBackground=(HBRUSH)(COLOR_WINDOW+1);

wclpszClassName=TEXT("WindowClass");

wchIcon=LoadIcon(NULL,IDI_APPLICATION);

wchIconSm=LoadIcon(NULL,IDI_APPLICATION);

if(!RegisterClassEx(&wc))

{

MessageBox(NULL,TEXT("窗口注册失败!"),TEXT("错误"),MB_ICONEXCLAMATION|MB_OK);

return 0;

}

GetWindowRect(GetDesktopWindow(),&rdesk);

x=(rdeskright-Width)/2;

y=(rdeskbottom-Height)/2,

hwnd = CreateWindowEx(WS_EX_TOPMOST,

TEXT("WindowClass"),

TEXT("I Love You"),

WS_THICKFRAME|WS_VISIBLE,

x,

y,

Width,

Height,

NULL,NULL,hInstance,NULL);

if(NULL==hwnd)

{

MessageBox(NULL,TEXT("窗口创建失败!"),TEXT("错误!"),MB_ICONEXCLAMATION|MB_OK);

return 0;

}

while(GetMessage(&msg,NULL,0,0)>0)

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

return msgwParam;

}

截图

欢迎分享,转载请注明来源:浪漫分享网

原文地址:https://hunlipic.com/langman/593756.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-07-05
下一篇2023-07-05

发表评论

登录后才能评论

评论列表(0条)

    保存