对于初学C语言的人来说,使用VC++60编写简单的程序再合适不过了,那么我们一起来看一下怎么使用VC++60来创建,编写和运行一个简单的C语言程序吧。
01点击电脑左下角开始,运行VC++60程序。
02单击”文件“菜单项,选择子菜单”新建“,进入新建界面。
03由于早期学习只需要控制台应用程序,我们选择Win32 Console Application。
04选择空工程利于自己学习
05再新建C++ Source File(C++ 源文件) 。
06然后键入代码:#include <stdioh>int main ()<
printf ("Hello , world!n");return 0;
07最后按红色的感叹号或者按快捷键可直接编译连接并运行
08运行成功。
特别提示常见小问题:can not open file debug/exe
问题:执行Linkexe时出错,主要问题是计算机权限不足。
解决方案:右键桌面的vc快捷方式,点“兼容性”,勾选“以管理员身份运行”并应用
如果怎么都不能运行,那么就是你的工作空间创建在了vc默认的MyProjects工作区,这样会有很多问题。所以在创建工作空间的时候一定要选一个自己的文件夹,最好不要有中文。
#include <windowsh>
#define APPNAME "HELLO_WIN"
char szAppName[] = APPNAME; // 应用程序的名称
char szTitle[] = APPNAME; // 标题行显示的文字
const char pWindowText;
void CenterWindow(HWND hWnd);
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message) {
case WM_CREATE:
CenterWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_RBUTTONUP:
DestroyWindow(hwnd);
break;
case WM_KEYDOWN:
if (VK_ESCAPE == wParam)
DestroyWindow(hwnd);
break;
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc;
RECT rc;
hdc = BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rc);
SetTextColor(hdc, RGB(240,240,96));
SetBkMode(hdc, TRANSPARENT);
DrawText(hdc, pWindowText, -1, &rc, DT_CENTER|DT_SINGLELINE|DT_VCENTER);
EndPaint(hwnd, &ps);
break;
}
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}
int APIENTRY WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow
)
{
MSG msg;
WNDCLASS wc;
HWND hwnd;
pWindowText = lpCmdLine[0] lpCmdLine : "这是一个Windows窗体";
ZeroMemory(&wc, sizeof wc);
wchInstance = hInstance;
wclpszClassName = szAppName;
wclpfnWndProc = (WNDPROC)WndProc;
wcstyle = CS_DBLCLKS|CS_VREDRAW|CS_HREDRAW;
wchbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
wchIcon = LoadIcon(NULL, IDI_APPLICATION);
wchCursor = LoadCursor(NULL, IDC_ARROW);
if (FALSE == RegisterClass(&wc))
return 0;
hwnd = CreateWindow(
szAppName,
szTitle,
WS_OVERLAPPEDWINDOW|WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
360,//CW_USEDEFAULT,
240,//CW_USEDEFAULT,
0,
0,
hInstance,
0);
if (NULL == hwnd)
return 0;
while (GetMessage(&msg, NULL, 0, 0) > 0) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msgwParam;
}
void CenterWindow(HWND hwnd_self)
{
HWND hwnd_parent;
RECT rw_self, rc_parent, rw_parent;
int xpos, ypos;
hwnd_parent = GetParent(hwnd_self);
if (NULL == hwnd_parent)
hwnd_parent = GetDesktopWindow();
GetWindowRect(hwnd_parent, &rw_parent);
GetClientRect(hwnd_parent, &rc_parent);
GetWindowRect(hwnd_self, &rw_self);
xpos = rw_parentleft + (rc_parentright + rw_selfleft - rw_selfright) / 2;
ypos = rw_parenttop + (rc_parentbottom + rw_selftop - rw_selfbottom) / 2;
SetWindowPos(
hwnd_self, NULL,
xpos, ypos, 0, 0,
SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE
);
}
120行,不知道够不够。如果你加上一些注释,可以达到150行。
以上代码,只是显示一行 “这是一个Windows窗体” 的黑色底色的窗体,窗体的标题是“HELLO_WIN”。
#include "stdafxh"
#include <iostream>
#include <timeh>
using namespace std;
#define M 10
#define N 10
int main()
{
int m, n,x;
float num[M][N],min;
cout << "请输入m、n的值:" << endl;
cin >> m >> n;
void output(float a[][10], int b, int c);
float findmin(float a[][10], int b, int c);
srand(time(NULL));
for(int i=0;i<m;i++)
for (int j = 0; j < n; j++)
{
x = rand() % 100 + 1;
num[i][j] =(float) x / 100+rand()%100; //100以内小数
}
output(num, m, n);
min = findmin(num, m, n);
system("pause");
return 0;
}
void output(float a[][10], int b, int c)
{
for (int i = 0; i < b; i++)
{
for (int j = 0; j < c; j++)
printf("%42f ",a[i][j]);
cout << endl;
}
}
float findmin(float a[][10], int b, int c)
{
float min = 100;
int p, q;
for (int i = 0; i < b; i++)
{
for (int j = 0; j < c; j++)
{
if (a[i][j] < min)
{
min = a[i][j];
p = i;
q = j;
}
}
}
cout << "最小数在第" << p << "行第" << q << "列,该数是:" << min<<endl;
return min;
}
以上就是关于C语言程序设计教程全部的内容,包括:C语言程序设计教程、150行左右的c语言程序设计,简单一点的,大一的作业,帮帮忙。、C语言编程题 求代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)