i need to know an example of writting a program in c language under linux using threads?
397803
/*\n\ni need to know an example of writting a program in c\nlanguage under linux using threads?\n\nwrite aprogram to calculate the result of the equation\nY=3sin(x)+6cos(x)+5x2 so each term accomplished by a\nthread. The main thread will calculate the result.\n\n*/\n\n\n#include <pthread.h>\n#include <math.h>\n#include <stdlib.h>\n#include <stdio.h>\n\n/* static global location -- all threads will read */\nstatic double x;\n\nstatic void*\nthree_sinx(void*p)\n{\n  double* result = (double*)p;\n  *result = 3 * sin(x);\n  return 0;\n}\n\nstatic void*\nsix_cosx(void*p)\n{\n  double* result = (double*)p;\n  *result = 6 * cos(x);\n  return 0;\n}\n\nstatic void*\nfive_x_squared(void*p)\n{\n  double* result = (double*)p;\n  *result = 5 * x * x;\n  return 0;\n}\n\n/*\n *\n * Y = 3sin(x) + 6cos(x) + 5x2\n *\n */\n\nint\nmain(int argc, char* argv[])\n{\n  double result[3]; /* one location for each thread */\n  pthread_t tid[3];\n  void *r;\n  int i;\n\n  /* Set "x" to double value passed in on command line */\n  x = argc>1 ? strtod(argv[1], 0) : 0;\n\n\n  /*\n   *  Since result areas are distinct, no mutex needed\n   */\n  if (pthread_create(&tid[0], NULL,\n    three_sinx, &result[0]) != 0) {\n    perror("pthread_create[0]"), exit(-1);\n  }\n\n  if (pthread_create(&tid[1], NULL,\n    six_cosx, &result[1]) != 0) {\n    perror("pthread_create[1]"), exit(-1);\n  }\n\n  if (pthread_create(&tid[2], NULL,\n    five_x_squared, &result[2]) != 0) {\n    perror("pthread_create[2]"), exit(-1);\n  }\n\n  /* Synchronize on the completing child threads */\n  for (i=0; i<3; i++) {\n    if (pthread_join(tid[i], &r) != 0) {\n      perror("pthread_join");\n      exit(-1);\n    }\n  }\n\n  /* main thread will now combine the result */\n  printf("For y=3sin(x)+6cos(x)+5x2, when x=%f, y=%f&#92;n",\n      x, result[0]+result[1]+result[2]);\n\n  return 0;\n}\n\n\n\nTo show that it works:\n\n$ cc pthr.c -lpthread -lm\n\n$ a.out 3.14159\nFor y=3sin(x)+6cos(x)+5x2, when x=3.141590, y=43.347947\n\n$ a.out 0\nFor y=3sin(x)+6cos(x)+5x2, when x=0.000000, y=6.000000
346423
check out http://www.planet-source-code.com - I don't do C++, but I use that site all the time, and it has great examples in source code form.
781094
Nobody is going to do your homework for you. \n\nIf you're supposed to write code examples that illustrate how two comparable programs might look, then do this. Write some simple programs in C, and then re-write the same program in C++ but put the functions your void main calls in a class and instantiate the class.
1008869
#include <stdio.h>\n#include <dos.h>\n#include <conio.h>\n\n/********************************************/\n/*This program set the parallel port outputs*/\n/********************************************/\n\nvoid main (void)\n{\nclrscr();             /* clear screen */\noutportb(0x378,0xff); /* output the data to parallel port */\ngetch();              /* wait for keypress before exiting */\n}\n\njust check here you can get all info http://www.epanorama.net/circuits/parallel_output.html
742648
#include<stdio.h>\n#include<conio.h>\nvoid main()\n{\nint n=5,i,j;\nclrscr();\nfor(i=1;i<=2*n-2;i++)\n{\nprintf(" ");\n}\nprintf("1&#92;n");\nfor(i=2;i<=n-1;i++)\n{\nfor(j = 1;j<=(n-i)*2;j++)\nprintf(" ");\nfor(j = i;j<=2*i-1;j++)\n{\nprintf("%d ",j);\n}\nfor(j = 2*i-2;j>=i;j--)\n{\nprintf("%d ",j);\n}\nprintf("&#92;n");\n}\nfor(i = n;i<=2*n-1;i++)\nprintf("%d ",i);\nfor(i = 2*n-2;i>=n;i--)\nprintf("%d ",i);\ngetch();\n}
1028478
Get a book to teach you C and then go from there. You can use a free compiler such as gcc to get you on your way.
299602
Try and use an IDE if you can. Or switch to linux for programming, you wont have to use getch() or pause :)
162888
if u need any programs in C language..then please send me the questions..I will mail u the solution code..
885562
I'm a computer science major at the university of louisiana at lafayette.  Our computer lab that we write our programming assignments all have linux enviornments.  Our introductory level course is taught in C++.\n\nThere are two main compilers that we use.  one is the GNU compiler (g++).  I'll reference the link for the website.\n\n;-)
979933
I'm giving u the program (in C), just go through it, then write the algo. It'll be easier.\n\n// Program :  MERGE  SORT\n\n#include<stdio.h>\n#include<conio.h>\n\nvoid mergesort(int *,int);\n\nvoid main()\n{\nint x[30],n,i;\nclrscr();\nprintf("Enter total no. of elements");\nscanf("%d",&n);\nprintf("Enter %d nos.",n);\nfor(i=0;i<n;i++)\n   scanf("%d",&x[i]);\n\nmergesort(x,n);\n\nprintf("After sorting in descending order :&#92;n");\nfor(i=n-1;i>=0;i--)\n  printf(" %d",x[i]);\n\ngetch();\n}\n\n\n\nvoid mergesort(int x[],int n)\n{\n  int aux[30],l1,l2,u1,u2,i,j,k,size;\n  size=1;   // merges file of size 1\n  while(size<n)\n  {\n    l1=0;   // initialize lower-bound of 1st. file\n    k=0;    // k is index for auxilliary array\n    while(l1+size<n)\n    {\n      // initialize remaining parameters...\n      l2=l1+size;\n      u1=l2-1;\n      u2=(l2+size-1)<n ? (l2+size-1):(n-1);\n      for(i=l1,j=l2;i<=u1 && j<=u2;k++)\n if(x[i]<=x[j])\n   aux[k]=x[i++];\n else\n   aux[k]=x[j++];\n      while(i<=u1)\n      aux[k++]=x[i++];\n      while(j<=u2)\n      aux[k++]=x[j++];\n\n      l1=u2+1;\n    } /* end of 2nd. while-loop */\n    for(i=l1;k<n;i++)\n       aux[k++]=x[i];\n    for(i=0;i<n;i++)\n       x[i]=aux[i];\n\n    size*=2;\n  } /* end of 1st. while-loop */\n}
348911
#include <stdio.h>\n#include <strings.h>\n\nint\nmain(int argc, char* argv[])\n{\n  char *token, *string = argv[1];\n  int count = 0;\n\n  while ((token=strtok(string, "&#92;t ")) != 0) {\n    count++;\n    string = 0;\n  }\n    \n  printf("String has %d words&#92;n", count);\n\n  return 0;\n}\n\n\nAnd to show that it works:\n\n$ cc cw.c\n\n$ a.out "this is a simple test"\nString has 5 words
438944
#include<stdio.h>\n#include<conio.h>\n#include<ctype.h>\n\nint main()\n{\n  char ch;\n  cout<<"enter some text&#92;n";\n  do{\n    ch=getch();\n    putchar(ch);\n  }while(ch!='&#92;n');\n  return 0;\n}
1077694
I suggest you visit a site like www.sourceforge.org or www.programmersheaven.com. There are many open-source, game projects written in C.
236736
I do not think an operating system can be fully written in high level laguages. It's kernel needs a lot of machine code withc is the lowest level you can go with a language. Now it depends on what languages you actualy mean by high level. C/C++ are high level languages and Linux's kernel for example is written in C++ (witch also supports machine code to be inserted). If we leave the kernel alone (witch is the most importent part in the OS), some other modules of the OS can be written in , let's say Basic or even Haskell. The disadvantages of these languages is that programs written with them will be slower, significantly in some cases, witch is not usualy bad because programmer time is more exensive than processor time. So if a programmer takes a week to write a program in C++ and only one day in Haskell, it will not matter if the Haskel program will run 20% if it's a program used just to give a result for example. However in operating system there are a lot of time-critical modules (memory management, disk management etc) .. so basicly al the time the computer will run slower.
706549
Try to read the common inside the code.(inside the "/*.... */")\n\nThis function do couple of things:\n1. It is to check the input command.\n2. Set the parent thread to wait. \n3. Create a child thread.\n4. Use the child thread to run the command.
345718
int main (void)\n{\nint a,rem\ncout<<"enter the number";\n<<cin a;\nrem=a/a;\nif(rem>0)\ncout<<"its integer";\nelse\ncout<<"not a integer";\nreturn 0;\n}
160699
#include <iostream.h>\n#include <fstream.h>\n\nvoid main()\n{\n  ofstream output;\n  output.open("outpu.dat");\n\n  output << "Ouput test data";\n\n  output.close();\n}