1.编程 c 怎么写出一个v型代码既然是简单计算器,只需要实现加减乘除,同时每次支持两个操作数和一个操作符 。
同时约定,操作数为整型,对于加减乘输出为整型,除法输入为浮点型即可 。对于输入输出和计算,提供如下代码:#include int main(){ int a,b,r; float r_div; char op; scanf("%d",&a);//读入操作数a op = getchar();//读入运算符号 scanf("%d",&b);//读入操作数b switch(op)//根据运算符号,进行对应的加减乘除运算 。
{ case '+': r = a+b;//加法 break; case '-': r = a-b;//减法 break; case '*': r = a*b;//乘法 break; case '/': r_div = a/(float)b;//除法 break; default: printf("unknow operator\n");//未知操作符,属于输入错误 。退出程序 。
return -1; } //根据操作符号,输入对应的运行结果 。if(op == '/')printf("%d%c%d=%f\n", a,op,b,r_div); else printf("%d%c%d=%d\n", a,op,b,r); return 0;}以上代码就实现了最简单的计算器,可以根据需要,在其上增加其它功能,比如连续计算,或者括号支持等 。
2.在VC++中怎么编写C程序估计你用的是VC++6.0基于控制台的编程吧?
VC++6.0基于控制台的编程标准步骤是:先建立一个工程(又叫工作区间,英文名workspace),然后在这个工程里添加头文件(.h文件)源程序文件(.cpp)文件等等.
我把常用的步骤叙述一下:
1.打开VC++
2.建立工程:点File->New,选Project标签,在列表中选Win32 Console Application,再在右边的框里为工程起好名字,选好路径,点OK->finish.至此工程建立完毕.
【vc怎么开始写代码】3.创建源文件或头文件:点File->New,选File标签,在列表里选C/C++ Header File或者C++ Source File或者别的.给文件起好名字,选好路径,点OK.至此一个源文件就被添加到了你刚创建的工程之中.
4.写好代码
5.编译->链接->调试
此外,C语言的代码可以直接复制到VC++中使用,但最好别用C中那个清屏的函数,在VC++中这个函数被包含在了另外的头文件中
3.这个简单的VC++代码该怎么写#include "stdafx.h"#include "resource.h"#define MAX_LOADSTRING 100// Global Variables:HINSTANCE hInst; // current instanceTCHAR szTitle[MAX_LOADSTRING]; // The title bar textTCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text// Foward declarations of functions included in this code module:ATOM MyRegisterClass(HINSTANCE hInstance);BOOL InitInstance(HINSTANCE, int);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ // TODO: Place code here. MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_SF, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_SF); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam;}//// FUNCTION: MyRegisterClass()//// PURPOSE: Registers the window class.//// COMMENTS://// This function and its usage is only necessary if you want this code// to be compatible with Win32 systems prior to the 'RegisterClassEx'// function that was added to Windows 95. It is important to call this function// so that the application will get 'well formed' small icons associated// with it.//ATOM MyRegisterClass(HINSTANCE hInstance){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_SF); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_SF; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex);}//// FUNCTION: InitInstance(HANDLE, int)//// PURPOSE: Saves instance handle and creates main window//// COMMENTS://// In this function, we save the instance handle in a global variable and// create and display the main program window.//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){ HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;}//// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)//// PURPOSE: Processes messages for the main window.//// WM_COMMAND - process the application menu// WM_PAINT - Paint the main window// WM_DESTROY - post a quit message and return////LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here 。
- wpsoffice怎么写论文
- 窗字的篆体怎么写
- 午字篆书怎么写
- 小花狗的日记怎么写
- 关于简历的英文论文怎么写的
- biang这个字怎么写
- 论文摘要怎么写工科
- 抬款借条怎么写
- 谋的笔顺怎么写
- 怎么写原电池反应式