コメント一覧
まえへ つぎへ79 投稿者:
名無しさん 2019/12/17 11:07:59
ここで一句
80 投稿者:
名無しさん 2019/12/17 11:08:12
//1
#include <stdio.h>
#include <math.h>
float f1(float x,float y) {
return(x+y);
}
int main(void) {
int i;
float x[100],y[100],h=0.2,r;
x[0]=0.0;
y[0]=0.0;
i=0;
printf(" x , y (error)\n");
do {
x[i+1]=x[i]+h;
y[i+1]=y[i]+f1(x[i],y[i])*h;
i++;
r=exp(x[i])-x[i]-1;
printf("%f, %f (%f)\n",x[i],y[i],r-y[i]);
} while(x[i]<1.0);
}
81 投稿者:
名無しさん 2019/12/17 11:08:27
//2
#include <stdio.h>
#include <math.h>
float f1(float x,float y) {
return(x+y);
}
int main(void) {
int i;
float x[100],y[100],h=0.2,r;
x[0]=0.0;
y[0]=0.0;
i=0;
printf(" x , y (error)\n");
do {
x[i+1]=x[i]+h;
y[i+1]=y[i]+f1(x[i],y[i])*h;
y[i+1]=y[i]+(f1(x[i],y[i])
+f1(x[i+1],y[i+1]))*h/2.0;
i++;
r=exp(x[i])-x[i]-1;
printf("%f, %f (%f)\n",x[i],y[i],r-y[i]);
} while(x[i]<1.0);
}
82 投稿者:
名無しさん 2019/12/17 11:08:38
//3
#include <stdio.h>
#include <math.h>
float f1(float x,float y) {
return(x+y);
}
int main(void) {
int i;
float x[100],y[100],h=0.2,r,A,B,C,D;
x[0]=0.0;
y[0]=0.0;
i=0;
printf(" x , y (error)\n");
do {
x[i+1]=x[i]+h;
A=h*f1(x[i],y[i]);
B=h*f1(x[i]+h/2.0,y[i]+A/2.0);
C=h*f1(x[i]+h/2.0,y[i]+B/2.0);
D=h*f1(x[i]+h,y[i]+C);
y[i+1]=y[i]+(A+2.0*B+2.0*C+D)/6.0;
i++;
r=exp(x[i])-x[i]-1;
printf("%f, %f (%f)\n",x[i],y[i],r-y[i]);
} while(x[i]<1.0);
}
83 投稿者:
名無しさん 2019/12/18 14:35:32
https://drive.mimoex.net/index.php/s/EdwQeMynrNCepeC
84 投稿者:
名無しさん 2019/12/23 09:08:33
case WMLCOMMAND:
switch (LOWORD(wp)){
case IDOK:
case IDCANCEL:
nRtn = MessageBox(hDlog, TEXT("Can I quit?"), szAppName, MB_OKCANCEL | MB_ICONQUESTION);
if (nRtn == IDCANSEL){
return TRUE;
}
if (bSocket){
if (bSanka){
wsprintf(szBuf, TEXT("#%s"), szName);
addrlen = (int)sizeof(addr);
sendto(s, szBuf, (int)strlen(szBuf), 0, (SOCKADDR *)&addr, addrlen);
bSanka = FALSE;
}
if (closesocket(s) != 0){
MessageBox(hDlg, TEXT("socke close faled"), szAppName, MB_OK);
}
}
EndDialog(hDlg, IDOK);
return TRUE;
caseIDC_SENDBTN:
GetDlgItemText(hDlg, IDC_SEND, szBuf, sizeof(szBuf));
if (strcmp(szBuf, "") == 0){
MessageBox(hDlg, TEXT("No entry"), szAppName, MB_OK);
return TRUE;
}
if (bFirst){
wsprintf(szTemp, TEXT("!%s+%s"), szName, szBuf);
strcpy_s(szBuf, szTemp);
bFirst = FALSE
}
else{
wsprintf(szTemp, TEXT("%s:%s"), szName, szBuf);
strcpy_s(szBuf, szTemp);
}
addrlen = (int)sizeof(addr);
nRtn = sendto(s, szBuf, (int)strlen(szBuf), 0, (SOCKADDR *)&addr, addrlen);
if (nRtn == SOCKET_ERROR){
MessageBox(hDlg, TEXT("send faled"), szAppName, MB_OK);
return TRUE;
}
SetDlgItemText(hDlg, IDC_SEND, "");
SetFocus(GetDlgItem(hDlg, IDC_SEND));
return TRUE;
case IDC_START:
port = (u_short)GetDlgItemInt(hDlg, IDC_PORT, &bSuccess, FALSE);
if (port == 0){
MessageBox(hDlg, TEXT("Invalid port number"), szAppName, MB_OK);
return TRUE;
}
GetDlgItemText(hDlg, IDC_SERVER, szServer, (int)sizeof(szServer));
if (strcmp(szServer, "") == 0){
MessageBox(hDlg, TEXT("Invalid port name"), szAppName, MB_OK);
}
GetDlgItemText(hDlg, IDC_NAME, szServer, (int)sizeof(szServer));
if (strcmp(szName, "") == 0){
MessageBox(hDlg, TEXT("Invalid ID"), szAppName, MB_OK);
return TRUE;
}
lpHostEnt = gethostbyname(szServer);
if (lpHostEnt == NULL){
messageBox(hDlg, TEXT("cant found server"), szAppName, MB_OK);
return TRUE;
}
}
memset(&addr, 0, sizeof(addr));
addr.sin_port = htons(port);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = *((unsigned long *)lpHostEnt->h_addr);
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == INVALID_SOCKET){
MessageBox(hDlg, TEXT("cannot open socket"), szAppName, MB_OK);
return TRUE;
}
bSocket = TRUE;
nRtn = WSAAsyncSelect(s, hDlg, MY_MSG, FD_READ | FD_WRITE);
if (nRtn == SOCKET_ERROR){
nError = WSAGetLastError();
if (nError != WSAEWOULDBLOCK){
MessageBox(hDlg, TEXT("Desynchronization failure"), szAppName, MB_OK);
closesocket(s);
bSocket = FALSE;
}
}
EnableWindow(GetDlgItem(hDlg, IDC_START), FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_SENDBTN), TRUE);
SendMessage(GetDlgItem(hDlg, IDC_PORT), EM_SETREADONLY, (WPARAM)TRUE, 0)
SendMessage(GetDlgItem(hDlg, IDC_SERVER), EM_SETREADONLY, (WPARAM)TRUE, 0)
SendMessage(GetDlgItem(hDlg, IDC_NAME), EM_SETREADONLY, (WPARAM)TRUE, 0)
SetFocus(GetDlgItem(gDlg, IDC_SEND));
return TRUE;
}
return FALSE;
}
return FALSE;
}
85 投稿者:
名無しさん 2019/12/23 09:09:18
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN
#define MY_MSG (WM_USER + 1)
#define MAX_RECORD 64 * 1024
#include <Windows.h>
#include <windowsx.h>
#include <winsock2.h>
#include "resource.h"
BOOL CALLBACK MyClientProc(HWND, UINT, WPARAM, LPARAM);
char szAppName[] = "クライアント";
BOOL bSocket = FALSE;
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow){
WSADATA wsaData;
hInst = hCurInst;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0){
MessageBox(NULL, TEXT("スタートアップ失敗"), szAppName, MB_OK);
return -1;
}
DialogBox(hCurInst, TEXT("CLIENT"), NULL, (DLGPROC)MyClientProc);
if (WSACleanup() != 0){
MessageBox(NULL, TEXT("クリーンアップ失敗"), szAppName, MB_OK);
return -2;
}
return 0;
BOOL CALLBACK MyClientProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp){
static SOCKET s;
u_short port;
unsigned int address;
char szServer[64];
HOSTENT *lpHostEnt;
BOOL bSuccess;
static SOCKADDR_IN addr;
int nRtn, nError, nEvent;
int addrlen;
char szBuf[1024], szTemp[1024];
static char szAllBuf[MAX_RECORD], szName[64];
static BOOL bFirst = TRUE;
HICON hIcon;
static BOOL bSanka = FALSE;
switch (msg){
case WM_INITDIALOG:
hIcon = (HICON)LoadImage(hInst, TEXT("MYICON"), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_SHARED);
SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
EnableWindow(GetDlgItem(hDlg, IDC_SENDBTN), FALSE);
SendMessage(GetDlgItem(hDlg, IDC_INFO), EM_LIMITTEXT, (WPARAM)MAX_RECORD, 0);
SendMessage(GetDlgItem(hDlg, IDC_SEND), EM_LIMITTEXT, (WPARAM)1024, 0);
return TRUE;
case MY_MSG:
nEvent = WSAGETSELECTEVENT(lp);
switch (nEvent){
case FD_READ:
addrlen = (int)sizeof(addr);
nRtn = recvfrom(s, szBuf, (int)sizeof(szBuf) - 1, 0, (SOCKADDR *)&addr, &addrlen);
if (nRtn == SOCKET_ERROR){
MessageBox(hDlg, TEXT("受信エラーです"), szAppName, MB_OK);
return TRUE;
}
szBuf[nRtn] = '\0';
if (strcmp(szBuf, "ログインが許可されました") == 0){
bSanka = TRUE;
}
wsprintf(szTemp, TEXT("%s\r\n"), szBuf);
strcat_s(szAllBuf, szTemp);
Set DlgItemText(hDlg, IDC_INFO, szAllBuf);
SendMessage(GetDigItem(hD1g, IDC_INFO), EM_LINESCROLL, 0, Edit_GetLineCount(GetDlgItem(hDlg, IDC_INFO)));
if ((int)strlen(szAllBuf) > MAX_RECORD - 1024){
MessageBox(hDlg, TEXT("バッファをクリアします"), szAppName, MB_OK);
strcpy_s(szAllBuf, "");
SetWindowText(GetDlgItem(hDlg, IDC_INFO), szAllBuf);
if (strcmp(szBuf, "定員オーバーでログインできません") == 0) {
MessageBox(hDlg, TEXT("後でもう一度ログインしてください"), szAppName, MB_OK);
EnableWindow(GetDlgItem(hDig, IDC_SENDBTN), FALSE);
EnableWindow(GetDigItem(hDig, IDC_START), TRUE);
SendMessage(GetDigItem(hD1g, IDC_PORT), EM_SETREADONLY, (WPARAM)FALSE, 0);
SendMessage(GetDigItem(hDlg, IDC_SERVER), EM_SETREADONLY, (WPARAM)FALSE, 0);
SendMessage(GetDigItem(hDlg, IDC_NAME), EM_SETREADONLY, (WPARAM)FALSE, 0);
SetFocus(GetDigItem(hD1g, IDC_START));
bFirst = TRUE;
return TRUE;
}
break;
return TRUE;
86 投稿者:
名無しさん 2019/12/23 09:47:47
#define _WINSOCK_DEPRECATED_NO_WARNINGS
#define WIN32_LEAN_AND_MEAN
#define MY_MSG (WM_USER + 1)
#define MAX_RECORD 64 * 1024
#include <Windows.h>
#include <windowsx.h>
#include <winsock2.h>
#include "resource.h"
BOOL CALLBACK MyClientProc(HWND, UINT, WPARAM, LPARAM);
char szAppName[] = "クライアント";
BOOL bSocket = FALSE;
HINSTANCE hInst;
int WINAPI WinMain(HINSTANCE hCurInst, HINSTANCE hPrevInst, LPSTR lpsCmdLine, int nCmdShow){
WSADATA wsaData;
hInst = hCurInst;
if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0){
MessageBox(NULL, TEXT("スタートアップ失敗"), szAppName, MB_OK);
return -1;
}
DialogBox(hCurInst, TEXT("CLIENT"), NULL, (DLGPROC)MyClientProc);
if (WSACleanup() != 0){
MessageBox(NULL, TEXT("クリーンアップ失敗"), szAppName, MB_OK);
return -2;
}
return 0;
}
BOOL CALLBACK MyClientProc(HWND hDlg, UINT msg, WPARAM wp, LPARAM lp){
static SOCKET s;
u_short port;
unsigned int address;
char szServer[64];
HOSTENT *lpHostEnt;
BOOL bSuccess;
static SOCKADDR_IN addr;
int nRtn, nError, nEvent;
int addrlen;
char szBuf[1024], szTemp[1024];
static char szAllBuf[MAX_RECORD], szName[64];
static BOOL bFirst = TRUE;
HICON hIcon;
static BOOL bSanka = FALSE;
switch (msg){
case WM_INITDIALOG:
hIcon = (HICON)LoadImage(hInst, TEXT("MYICON"), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR | LR_SHARED);
SendMessage(hDlg, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)hIcon);
EnableWindow(GetDlgItem(hDlg, IDC_SENDBTN), FALSE);
SendMessage(GetDlgItem(hDlg, IDC_INFO), EM_LIMITTEXT, (WPARAM)MAX_RECORD, 0);
SendMessage(GetDlgItem(hDlg, IDC_SEND), EM_LIMITTEXT, (WPARAM)1024, 0);
return TRUE;
case MY_MSG:
nEvent = WSAGETSELECTEVENT(lp);
switch (nEvent){
case FD_READ:
addrlen = (int)sizeof(addr);
nRtn = recvfrom(s, szBuf, (int)sizeof(szBuf) - 1, 0, (SOCKADDR *)&addr, &addrlen);
if (nRtn == SOCKET_ERROR){
MessageBox(hDlg, TEXT("受信エラーです"), szAppName, MB_OK);
return TRUE;
}
szBuf[nRtn] = '\0';
if (strcmp(szBuf, "ログインが許可されました") == 0){
bSanka = TRUE;
}
wsprintf(szTemp, TEXT("%s\r\n"), szBuf);
strcat_s(szAllBuf, szTemp);
SetDlgItemText(hDlg, IDC_INFO, szAllBuf);
SendMessage(GetDlgItem(hDlg, IDC_INFO), EM_LINESCROLL, 0, Edit_GetLineCount(GetDlgItem(hDlg, IDC_INFO)));
if ((int)strlen(szAllBuf) > MAX_RECORD - 1024){
MessageBox(hDlg, TEXT("バッファをクリアします"), szAppName, MB_OK);
strcpy_s(szAllBuf, "");
SetWindowText(GetDlgItem(hDlg, IDC_INFO), szAllBuf);
}
if (strcmp(szBuf, "定員オーバーでログインできません") == 0) {
MessageBox(hDlg, TEXT("後でもう一度ログインしてください"), szAppName, MB_OK);
EnableWindow(GetDlgItem(hDlg, IDC_SENDBTN), FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_START), TRUE);
SendMessage(GetDlgItem(hDlg, IDC_PORT), EM_SETREADONLY, (WPARAM)FALSE, 0);
SendMessage(GetDlgItem(hDlg, IDC_SERVER), EM_SETREADONLY, (WPARAM)FALSE, 0);
SendMessage(GetDlgItem(hDlg, IDC_NAME), EM_SETREADONLY, (WPARAM)FALSE, 0);
SetFocus(GetDlgItem(hDlg, IDC_START));
bFirst = TRUE;
return TRUE;
}
break;
}
return TRUE;
case WM_COMMAND:
switch (LOWORD(wp)){
case IDOK:
case IDCANCEL:
nRtn = MessageBox(hDlg, TEXT("Can I quit?"), szAppName, MB_OKCANCEL | MB_ICONQUESTION);
if (nRtn == IDCANCEL){
return TRUE;
}
if (bSocket){
if (bSocket){
wsprintf(szBuf, TEXT("#%s"), szName);
addrlen = (int)sizeof(addr);
sendto(s, szBuf, (int)strlen(szBuf), 0, (SOCKADDR *)&addr, addrlen);
bSanka = FALSE;
}
if (closesocket(s) != 0){
MessageBox(hDlg, TEXT("socke close faled"), szAppName, MB_OK);
}
}
EndDialog(hDlg, IDOK);
return TRUE;
case IDC_SENDBTN:
GetDlgItemText(hDlg, IDC_SEND, szBuf, sizeof(szBuf));
if (strcmp(szBuf, "") == 0){
MessageBox(hDlg, TEXT("No entry"), szAppName, MB_OK);
return TRUE;
}
if (bFirst){
wsprintf(szTemp, TEXT("!%s+%s"), szName, szBuf);
strcpy_s(szBuf, szTemp);
bFirst = FALSE;
}
else{
wsprintf(szTemp, TEXT("%s: %s"), szName, szBuf);
strcpy_s(szBuf, szTemp);
}
addrlen = (int)sizeof(addr);
nRtn = sendto(s, szBuf, (int)strlen(szBuf), 0, (SOCKADDR *)&addr, addrlen);
if (nRtn == SOCKET_ERROR){
MessageBox(hDlg, TEXT("send faled"), szAppName, MB_OK);
return TRUE;
}
SetDlgItemText(hDlg, IDC_SEND, "");
SetFocus(GetDlgItem(hDlg, IDC_SEND));
return TRUE;
case IDC_START:
port = (u_short)GetDlgItemInt(hDlg, IDC_PORT, &bSuccess, FALSE);
if (port == 0){
MessageBox(hDlg, TEXT("Invalid port number"), szAppName, MB_OK);
return TRUE;
}
GetDlgItemText(hDlg, IDC_SERVER, szServer, (int)sizeof(szServer));
if (strcmp(szServer, "") == 0){
MessageBox(hDlg, TEXT("Invalid port name"), szAppName, MB_OK);
}
GetDlgItemText(hDlg, IDC_NAME, szServer, (int)sizeof(szServer));
if (strcmp(szName, "") == 0){
MessageBox(hDlg, TEXT("Invalid ID"), szAppName, MB_OK);
return TRUE;
}
lpHostEnt = gethostbyname(szServer);
if (lpHostEnt == NULL){
address = inet_addr(szServer);
lpHostEnt = gethostbyaddr((char *)&address, 4, AF_INET);
if (lpHostEnt == NULL){
MessageBox(hDlg, TEXT("cant found server"), szAppName, MB_OK);
return TRUE;
}
}
memset(&addr, 0, sizeof(addr));
addr.sin_port = htons(port);
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = *((unsigned long *)lpHostEnt->h_addr);
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s == INVALID_SOCKET){
MessageBox(hDlg, TEXT("cannot open socket"), szAppName, MB_OK);
return TRUE;
}
bSocket = TRUE;
nRtn = WSAAsyncSelect(s, hDlg, MY_MSG, FD_READ | FD_WRITE);
if (nRtn == SOCKET_ERROR){
nError = WSAGetLastError();
if (nError != WSAEWOULDBLOCK){
MessageBox(hDlg, TEXT("Desynchronization failure"), szAppName, MB_OK);
closesocket(s);
bSocket = FALSE;
}
}
EnableWindow(GetDlgItem(hDlg, IDC_START), FALSE);
EnableWindow(GetDlgItem(hDlg, IDC_SENDBTN), TRUE);
SendMessage(GetDlgItem(hDlg, IDC_PORT), EM_SETREADONLY, (WPARAM)TRUE, 0);
SendMessage(GetDlgItem(hDlg, IDC_SERVER), EM_SETREADONLY, (WPARAM)TRUE, 0);
SendMessage(GetDlgItem(hDlg, IDC_NAME), EM_SETREADONLY, (WPARAM)TRUE, 0);
SetFocus(GetDlgItem(hDlg, IDC_SEND));
return TRUE;
}
return FALSE;
}
return FALSE;
}
87 投稿者:
名無しさん 2020/01/14 11:18:31
例
/* laplace */
#include <stdio.h>
#include <math.h>
#define N 3
int
main(void)
{
int i , j, m;
float u [N + 1][N + 1], U, er, d, h;
d = 12.0
h = d / N;
for (i = 0; i <= N; i++)
for (j = 0; j <= N; j++)
u[i][j] = 0.0;
for (i = 0; i <= N; i++) {
u[i][0] = 100.0;
u[0][i] = 100.0;
u[N][i] = 100.0;
}
m = 0;
do {
er = 0.0;
for (i = 1; i < N; i++) {
for (j = 1; j < N; j++) {
U = (u[i - 1][j] + u[i][j - 1]
+ u[i + 1][j] + u[i][j + 1]) / 4.0;
er += fabs(U - u[i][j]);
u[i][j] = U;
}
}
m++;
} while (er > 1.0e-4);
printf("%d\n", m);
for (j = N; j >= 0; j--) {
for (i = 0; i <= N; i++)
printf("%7.2f", u[i][j]);
printf("\n");
}
88 投稿者:
名無しさん 2020/01/14 12:09:32
/* laplace */
#include <stdio.h>
#include <math.h>
#define N 5
int main (void)
{
int i, j, m;
float u[N + 1][N + 1], U, er, d, h;
d = 1.0 ;
h = d / N;
for (i = 0; i <= N; i++)
for (j = 0; j <= N; j++)
u[i][j] = 0.0;
for (i = 0; i <= N; i++)
{
u[i][N] = sin(M_PI*h*i);
}
m = 0;
do
{
er = 0.0;
for (i = 1; i < N; i++)
{
for (j = 1; j < N; j++)
{
U = (u[i - 1][j] + u[i][j - 1]
+ u[i + 1][j] + u[i][j + 1]) / 4.0;
er += fabs (U - u[i][j]);
u[i][j] = U;
}
}
m++;
}
while (er > 1.0e-4);
printf ("%d\n", m);
for (j = N; j >= 0; j--)
{
for (i = 0; i <= N; i++)
printf ("%7.3f", u[i][j]);
printf ("\n");
}
}
/*
[e142122@ei1-pc15 ~/0114]$ 1
24
0.000 0.588 0.951 0.951 0.588 -0.000
0.000 0.318 0.515 0.515 0.318 0.000
0.000 0.170 0.275 0.275 0.170 0.000
0.000 0.087 0.140 0.140 0.087 0.000
0.000 0.036 0.059 0.059 0.036 0.000
0.000 0.000 0.000 0.000 0.000 0.000
*/