| | |
Random numbers (finding odd and even numbers)
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2008
Posts: 2
Reputation:
Solved Threads: 0
hello i have got little problem 
create a c program which starts with 3 processes the first proccess generates 50 random numbers and writes them inti common memory. the second proccess reads them and whrites the even numbers in file A,the odd numbers in file B.
i create first part of the program i also know how to find odd and even numbers
i know that i must insert "fd = open("blabla",O_RDWR|O_CREAT,0)" after "if" but my knowlodge isnt enogh 
thanks

create a c program which starts with 3 processes the first proccess generates 50 random numbers and writes them inti common memory. the second proccess reads them and whrites the even numbers in file A,the odd numbers in file B.
C Syntax (Toggle Plain Text)
#include <stdlib.h> #include <stdio.h> int main(void) { int A; srand(time(0)); for (A = 0; A < 50; ++A) { int number; number = rand(); printf("%d\n"); } return 0; }
C Syntax (Toggle Plain Text)
if ( x % 2 == 0 ) { //even } else { /odd }

thanks
don't use open(), instead use fopen() because FILE* and associated functions are much easier to use.
Here is a file i/o tutorial
Here is a file i/o tutorial
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Other Threads in the C Forum
- Previous Thread: Validating Algorithms
- Next Thread: End of file
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays asterisks binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile csyntax directory drawing dynamic executable fflush file fork frequency getlasterror givemetehcodez graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km lazy linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix microsoft motherboard multi mysql number open opendocumentformat opensource owf pattern pdf performance pointer pointers posix power problem probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming spoonfeeding stack standard string strings structures student suggestions systemcall test testautomation unix user variable voidmain() wab win32api windows.h






