دوستان کسی می تونه در رابطه با استراکچر ها و کاربردش و نوع تعریفش کمک کنه
ممنون میشم
Printable View
دوستان کسی می تونه در رابطه با استراکچر ها و کاربردش و نوع تعریفش کمک کنه
ممنون میشم
سلام.
فك كنم بهترين راه بررسي سورس باشه.
کد:#include<time.h>
#include<stdio.h>
#include<conio.h>
struct time{
int h;
int m;
int s;
};
void update(struct time *);
void display(struct time *);
void stop(void);
/////////////
main(){
long int x;
struct time tm={0};
while(1){
sleep(1);
update(&tm);
display(&tm);
}
}
///////////////
void update(struct time *p){
p->s++;
if(p->s==60){
p->s=0;
p->m++;
}
if(p->m==60){
p->m=0;
p->h++;
}
if(p->h==24)
p->h=0;
clrscr();
}
//////////////
void display(struct time *p){
printf("%d %d %d\n",p->h,p->m,p->s);
}
برنامه ای بنویسید که ریختن دو تاس را شبیه سازی کند این برنامه باید برای ریختن دو تاس دوبار ازتابع rand استفاده کند.(یک بار برای تاس اول و یک باربرای تاس دوم).سپس مجموع این دو مقدار محاسبه شود.برنامه شما باید دوتاس را 36000 بار بریزد.با استفاده از آرایه یک بعدی ، تعداد دفعاتی را که هر یک از مجموعه های ممکن ، پیش می آیند ثبت کرده و نتایج را به شکل جدولی چاپ کنید.اینو قبلا برنامشو با دوستان توی یکی دو تا پست قبلی نوشتیم که خب من خیلی متوجه راه حل نشدم . ولی خود آقای دایتل این مسئله رو اینجوری حل کردن .به نظر شما چرا آرایه ی expected رو اینجوری مقدار دهی کرده ؟ چرا از هر کدوم مقادیر 2 بار استفاده کرده ولی از 6 یک بار ؟؟؟
کد:
#include<iostream>
#include<iomanip>
using namespace std;
#include <ctime>
#include <cstdlib>
int main(){
const long rolls=36000;
const int size=13;
//array exepeted contains counts for the expected
//number of times each sum occurs in 36 rolls of the dice
int expected[size]={0,0,1,2,3,4,5,6,5,4,3,2,1};
int x,y,sum[size]={0};
srand(time(0));
for (long i=1;i<=rolls;i++){
x=rand()%6+1;
y=rand()%6+1;
sum[x+y]++;}
cout<<setw(10)<<"sum"<<setw(10)<<"total"<<setw(10)
<<"Expected"<<setw(10)<<"Actual\n"
<<setiosflags(ios::fixed |ios::showpoint );
for(int j=2;j<size;j++){
cout<<setw(10)<<j<<setw(10)<<sum[j]<<setprecision(3)
<<setw(9)<<100.0*expected[j]/36<<"%"<<setprecision(3)
<<setw(9)<<100.0*sum[j]/36000<<"%\n";}
return 0;
}
salam man so@li dastam va javbe on ra hamin alan mikham age lotfkonid bedin mamnon misham....barname benevisid ba estefade az dastore array va string yek reshte hc vorodi bekhanid be entehaye reshte@ ezafe konid
سلام دوستان کمک
برنامه ای بنویسید به عنوان حقوق کارمند اگر بالای 500باشه 10درصدمالیات و7درصد بیمه کم شه اگه حقوق بین 300 تا 500 باشه 7درصد مالیات و 5 درصد بیمه و اگر حقوق زیر 300 باشه 5درصد مالیات و3 درصد بیمه کسر شه خالص دریافتی بهمون بده ممنون میشم
سلام دوستان
میخوام بدونم چرا بورلند به
cin>>a[i][j]
گیر میده میگه Invalid indirection ؟:13:
#include <iostream.h>
int M(int a,int b)
{
int M[100],i,j;
for (i=1;i<=a;i++)
{ for (j=1;j<=b;j++)
cin>>a[i][j];
}
return M[100];
}
آه...:31:نقل قول:
چه اشتباهی...ببخشید.:46:
باید اینو مینوشتم:
#include <iostream.h>
int Mat(int a,int b)
{
int M[100][100];
int i,j;
for (i=1;i<=a;i++)
{ for (j=1;j<=b;j++)
cin>>M[i][j];
}
return M[100][100];}
سلام
من دارم یه برنامه مینویسم یه جاش رو گیر کردم : ضرب ماتریس n*n که باید ماتریس ها تو یه تابع فراخونی بشه.
دوستان راهنمایی کنید من چطور واسه این برنامه مقدار ماتریس رو که تابع گرفته به برنامه اصلی بازگردونم یعنی جلوی return چی بنویسم؟ مینویسم ;[A[n][m مقدار خونه n و m به برنامه اصلی داده میشه ؟!! چیکار کنم کل ماتریس رو به برنامه main برگردونه؟؟
int MAT(int n,int m)
{
int A[100][100],i,j;
for (i=1;i<=n;i++)
{for (j=1;j<=m;j++)
{cout<<"meghdare khane ("<<i<<","<<j<<") = ";
cin>>A[i][j];}
}
return
}
ممنون:11:
سلام دوستان
کلا کسی میدونه این سوالو من باید چیکار کنم ؟
Description
This puzzle consists of a random sequence of m black disks and n white disks on an oval-shaped track, with a turnstile capable of flipping (i.e., reversing) three consecutive disks. In Figure 1, there are 8 black disks and 10 white disks on the track. You may spin the turnstile to flip the three disks in it or shift one position clockwise for each of the disks on the track (Figure 1).
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
The goal of this puzzle is to gather the disks of the same color in adjacent positions using flips and shifts. (Figure 2)
[ برای مشاهده لینک ، با نام کاربری خود وارد شوید یا ثبت نام کنید ]
You are to write a program which decides whether a given sequence can reach a goal or not. If a goal is reachable, then write a message "YES"; otherwise, write a message "NO".
Input
The input consists of T test cases. The number of test cases ) (T is given in the first line of the input file. Each of the next T lines gives a test case. A test case consists of an integer, representing the sum of m and n, and a sequence of m+n 0s and 1s, representing an initial sequence. A 0 denotes a white disk and a 1 denotes a black disk. The sum of m and n is at least 10 and does not exceed 30. There is a space between numbers.
Output
The output should print either "YES" or "NO" for each test case, one per line.
Sample Input
2 18 0 0 1 0 1 1 1 1 0 1 0 0 1 0 0 0 0 1 14 1 1 0 0 1 1 1 0 0 1 1 0 1 0
Sample Output
YESNO
Source
ببینید برای اینگونه کارها بهتر از کانتینرهای پیش فرض مانند vector استفاده کنید، چون در غیر این صورت کار کمی پیچیده میشه، باید با استفاده از pointer ها این array رو بیرون بکشید، در مورد array های یک بعدی کار ساده هست و براحتی میشه این کار رو انجام داد، اما در مورد array های دو بعدی مانند مثال شما در واقع باید بگونه ای این کار رو انجام داد تا هم کامپایلر به شما ایراد نگیره و هم مشکل منطقی نداشته باشید، برای اینکار من مثال زیر رو براتون نوشتم نگاه کنید، امیدوارم کمکتون کنه:نقل قول:
امیدوارم با این مثال بتونید مشکلتون رو حل کنید.کد:#include <iostream>
using namespace std;
int** test(){
int **A=new int*[4];
for (int i=0; i<4; i++)
{
A[i] = new int[4];
for (int j=0; j<4; j++)
A[i][j]=i+j;
}
return A;
}
int main()
{
int **b=test();
cout <<b[2][3];
system("pause");
return 0;
}