برچسب‌ها

۱۳۸۸ دی ۲, چهارشنبه

برنامه تبدیل روز و ماه و سال شمسی به میلادی

توجه: این برنامه به زبان سی پلاس پلاس میباشد

// taghvim.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "resource.h"

#define MAX_LOADSTRING 100

// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR 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_TAGHVIM, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);

// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TAGHVIM);

// 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_TAGHVIM);
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = (LPCSTR)IDC_TAGHVIM;
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...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

// Mesage handler for about box.
LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;

case WM_COMMAND:
if (LOWORD(wParam) == IDOK LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return FALSE;
}

Coding by HOMAN ESTAKI

۱۳۸۸ آذر ۲۸, شنبه

برنامه ای که مضارب 5 قبل از عددی را میدهد

int main()
{
int n,i,t;
printf ("please insert a natural number :");
scanf("%d",&n);
t=n%5;
for(i=n-t;i>=0;i--)
{
i=i-5;
if(i<0)>
printf ("%d\t",i);
}
getch();
}

برنامه ای که اعداد صحیح بین دو عدد دریافتی از کاربر را نمایش میدهد

int main()
{
unsigned int i=1,a,b;
printf("insert a:");
scanf("%d",&a);
printf("insert b:");
scanf("%d",&b);
if(a
{
for(i=a;i<=b;i++)
printf(" %d ",i);
}
if(a>b)
{
for(i=b;i<=a;i++)
printf(" %d ",i);
}
else printf("0");
getch();
}

برنامه ای که عددی را دریافت اعداد فرد قبل آنرا نمایش میدهد

int main()
{
unsigned int i=1,n;
printf("insert n:");
scanf("%d",&n);
for(i=n;i<=n;i--)
{
i=i-1;if(i==0)
break;
printf(" %d ",i);
}
getch();
}

۱۳۸۸ آذر ۲۱, شنبه

برنامه محاسبه ی محیط و مساحت دایره با استفاده از یک تابع نوشته شده

float m(float);
float k;
void main()
{
float x;
float r;
printf("enter radius :");
scanf("%f",&r);
x=m(r);
printf("mohit=%.2f, masahat=%.2f",x,k);
getch();
}
/*-----------------------------*/
float m(float r)
{
int s;
s=2*3.14*r;
k=3.14*r*r;
return s;
}
coding by Mr.CHIZARI

جدول ضرب 10در10

int main()
{
int i,j;
for(i=1;i<=10;i++)
for(j=1;j<=10;j++)
printf("%d\t",i*j);
printf("\n");
getch();
}

برنامه ایکه 3 عدد را دریافت و مشخص میکند کدام بزرگتر و چندمین عدد است

int main()
{float a,b,c;
printf("pleas isert 3 number to compare :");
printf("insert a :");
scanf("%f",&a);
printf("insert b :");
scanf("%f",&b);
printf("insert c :");
scanf("%f",&c);
if(a>c && a>b)
printf("the large number is the first one (a)");
if(c>a && c>b)
printf("the large number is the third one (c)");
if(b>a && b>c)
printf("the large number is the second one (b)");
getch();
}

برنامه که اعداد اول قبل از عدد دریافتی را نمایش میدهد

void main()
{
int i,j,n,s=0;
printf("enter a number : ");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
for(j=2;j<=i/2;j++)
{
if(i%j==0)
s++;
}
if(s==0)
printf("%4d",i);
s=0;
}
getch();
}

coding by Mr.Chizari

۱۳۸۸ آذر ۱۵, یکشنبه

برنامه ضرب و جمع دو آرایه

int main()
{
int x[5],y[5],sum[5],m[5],i;
for(i=0;i<5;i++)
{ printf("Enter array[%d]",i);
scanf("%d",&x[i]);}
printf("\n");
for(i=0;i<5;i++)
{ printf("Enter array[%d]",i);
scanf("%d",&y[i]);}
for(i=0;i<5;i++){
printf("\n");
sum[i]=x[i]+y[i];
m[i]=x[i]*y[i];
printf("%d=sum %d=multiply",sum[i],m[i]);}
getch();
}

برنامه ای که زوج و فرد بودن عددی را نمایش میدهد

int main()
{
int n;
printf("please insert a number:");
scanf("%d",&n);
if(n%2==0)
printf("it is even");
else printf("it is odd");
getch();
}

برنامه ای که مربع n عدد را میدهد

int main()
{
int x, complex = 0, z = 0;
char answer = 'y';
while(answer == 'y')
{printf("\n\nEnter a number:");
scanf("%d",&x);
complex += x*x;
z ++;
printf("\n\n Do you want to continue?(y/n):");
answer = getche(); }
printf("\n\ncomplex of square is:%d",complex);
getch();
}

برنامه ای که تعداد حروف جمله ای را مشخص میکند

int main()
{
char x;
int y;
printf("insert your statement :\n");
for(y = 0; (x = getche())!='\r' ; y++) ;
printf("\n the letter of your statement is:%d",y) ;
getch();
}

برنامه ای که تعداد حروف و کلمه در جمله را مشخص میکند

int main()
{
int a = 0, b = 0;
char x;
printf("\n Enter a statement(ENTER):");
while((x = getche()) != '\r'){
a ++;
if(x == ' ')
b ++;
}
printf("\nleter=%d, word=%d", a-b, b+1);
getch();
return 0;
}

برنامه ای که عددی را دریافت و تا 0 انرا چاپ میکند

int main()
{
unsigned int i=1,n;
printf("insert n:");
scanf("%d",&n);
for(i=n;i<=n;i--)
printf(" %d ",i);
getch();
}

برنامه ای که فاکتوریل اعداد را میدهد

unsigned long myfactorial(int) ;
int main()
{
int s ;
printf(" enter a plus sign number:");
scanf("%d", &s);
printf("\n your number is =%d",s);
printf("factorial is = %1d",myfactorial(s));
getch();
return 0;
}

/*_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_*/


unsigned long myfactorial(int a)
{
if(a != 0)
return(a * myfactorial(a - 1)) ;
return 1 ;
}

۱۳۸۸ آذر ۱۴, شنبه

برنامه ای که تعداد ارقام یک عدد را میدهد

int main()
{
char x;
int y;
printf("insert a number :\n");
for(y = 0; (x = getche())!='\r' ; y++) ;
printf("\n the digit of your number is:%d",y) ;
getch();
}

برنامه تبدیلماه و سال به چندمین روز از سال

int main()
{
int m,d,n;
printf("enter month(m) and day(d)");
printf("\ninsert m:");
scanf("%d",&m);
printf("\ninsert d:");
scanf("%d",&d);
if(m<=6)
{n=(m-1)*31+d;
printf("\nnumber of day's year=%d",n);}
else
{n=(m-1)*30+6+d;
printf("\nnumber of day's year=%d",n);}
getch();
}

برنامه ی تبدیل روز به ساعت . دقیقه و ثانیه

int main()
{
int day,h,min,s;
printf("please insert your favorite number of day :\n\n");
scanf("%d",&day);
h=day*24;
min=h*60;
s=min*60;
printf("\n\n\n%d day is: \n\n%d hours and \n\n%d minutes \n\n%d seconds",day , h , min , s);
getch();
}

برنامه ی پرتاب تاس با حلقه ی switch

int game(void);
void main()
{
randomize();
int x,y;
int a1=0,a2=0,a3=0,a4=0,a5=0,a6=0;
int b1=0,b2=0,b3=0,b4=0,b5=0,b6=0;
while(1)
{
printf("\npress any key to strat the game...\n");
getch();
clrscr();
x=game();
y=game();
printf("\n\tthe first number = %d and second = %d\n\n",x,y);
switch(x)
{
case 1:
a1++;
printf("number of 1 = %d\n",a1);
break;
case 2:
a2++;
printf("number of 2 = %d\n",a2);
break;
case 3:
a3++;
printf("number of 3 = %d\n",a3);
break;
case 4:
a4++;
printf("number of 4 = %d\n",a4);
break;
case 5:
a5++;
printf("number of 5 = %d\n",a5);
break;
case 6:
a6++;
printf("number of 6 = %d\n",a6);
break;
}//end of switch
switch(y)
{
case 1:
b1++;
printf("number of 1 = %d\n",b1);
break;
case 2:
b2++;
printf("number of 2 = %d\n",b2);
break;
case 3:
b3++;
printf("number of 3 = %d\n",b3);
break;
case 4:
b4++;
printf("number of 4 = %d\n",b4);
break;
case 5:
b5++;
printf("number of 5 = %d\n",b5);
break;
case 6:
b6++;
printf("number of 6 = %d\n",b6);
break;
}//end of switch
}//end of while
}//end of main
//************************************************
int game(void)
{
int x;
x=random(6)+1;
return x;
}
Coding by Mr.CHIZARI

برنامه مشخص کننده اینکه عددی بر 3 یا 7 بخشپذیر است یا نه

int main()
{
int x;
printf("insert a number:");
scanf("%d",&x);
if(x%3==0)
printf("\nthe number on 3 is true");
else printf("\nthe number on 3 is false");
if(x%7==0)
printf("\n\nthe number on 7 is true");
else printf("\n\nthe number on 7 is false");
getch();
}