help plzzzzzzzzz in c language

hi everybody

i have two programs and i need your help to write the please write me the code as soon as possible.



Question 1:
Write a program that checks if an integer value entered by the user is present in a file or not. If present, the program should indicate the order of this value in the file i.e. it is value number 1, or value number 20 etc…
Your program should also check the file not found error case. In the first run shown below, the file was not in the folder. In the remaining runs, the file is there and the messages displayed by the program are shown. The number of values in the file is unknown. Assume that they are not repeated i.e. each value is written only once.



Note: You should stop searching once you find the value you are looking for. You can use a logical variable and keep looking for the value of the user as long as it is not found and you did not reach the end of the file. Both conditions should be included in the loop.

Question 2:

Write an interactive program that displays a menu ( use do-while) containing many choices as shown below:
1- split a real number
2- check if a number is perfect square
3- check if a number is prime
4- check if a number is odd
5- Exit
You have to write 5 functions as indicated below:
Function 1 to display the choices shown above.
Function 2 to receive a real value and return its whole part and decimal part separately (not print them); split function
Function 3 is a logical function that receives a positive integer number and returns 1 if it is perfect square, 0 otherwise. Perfect squares are 4,9,16,25 etc…
Function 4 is a logical function to receive a positive integer number and returns 1 if it is prime, 0 otherwise.
Function 5 is also a logical function to check if an integer number is odd or not.
In the main function, your program will ask the user to select a choice then, read the data and call the right function and print the right message. Sample runs of your programs are shown below.






for sample output

_ http://myfreefilehosting.com/f/7d74d2cea0_0.14MB


thanks for help .
I hope you mean C++ becasue this is a C++ forum and you said C.
closed account (z05DSL3A)
You are unlikely to get anyone to do your course work for you, if you have a specific question about a problem then post it, preferably with source code. If you show that you are trying to do the work people are more likely to help!
yogurt wrote:
>I hope you mean C++ becasue this is a C++ forum and you said C.

That may be true, but you can use C code in C++... In other words, give the C-style C++ answer (without the typecasting that C++ requires when using things like malloc() function), and it should be just fine.


Question 2:
Function 1 - This is easy. You can use printf() or puts() to output the menu.
Function 3 - You can use the sqrt() function in <math.h> to determine if an integer is a perfect square. If the result is an integer rather than something with decimal values after it, it is a perfect square.
Function 4 - You can do this one fairly easily too. A prime number is a number that isn't evenly divisible by any other number except 1 and itself. You first test for divisibility by 2. If it is evenly divisible by 2, it isn't prime. From there, you can loop through the odd numbers 3, 5, 7, etc. until you find that the number is not prime. Of course, if it makes it through the loop completely, then it is prime.
Function 5 - This one should be easy for you.

As for function 2, I'm unsure without using a structure or pointers, the latter of which should not be required for something like this. You might look into the div_t structure and the div() function found in <stdlib.h>, though the div_t structure uses an integer for the remainder. The remainder should be converted to a decimal by dividing by the original dividend. I recommend asking your instructor for some help with this one unless someone else can recommend something simpler than my suggestions. :P

That should at least get you started.

I hope this helps! ^_^

rpgfan
thanks for showing interest everybody

i meant c++ language sorry it was my mistake
On two conditions:

1) My bill rate is $150/hour, so I'll need an address to send the invoice.

2) You promise never, ever to work at the same company as me

can you check please what are my mistakes for the first question

#include<stdio.h>

int main () {

int x , z ;

FILE *infile ;

printf("enter the value you want") ;
scanf ("%d",&x) ;

infile = fopen("data.txt", "r") ;

fscanf(infile,"%d",&z) ;

while ( fscanf(infile,"%d",&z) !=EOF){

if(z==x){
printf ("the value exist in the file") ;

break ; }

else
printf("does not match") ;

}

fclose (infile) ;

return 0 ;


}
hey guys

any ideas about the second function
sorry rpgfan3233
i shouldn`t use that function you are talking about in function 2

any other idea (coded idea please !!)
Yes. It is really easily coded there: http://catb.org/~esr/faqs/smart-questions.html
Topic archived. No new replies allowed.