Skip to main content

Thread: Need help with linux/C


hi first post on forums, i'm doing course @ university called c programming under linux have gotten stuck on of questions , use bit of help.(linux question after c)

exercise 1
==========

find header file in value of pi defined.
how many digits precise pi implementation
have ?

hints: start finding c library glibc. there should
html-documentation of c library somewhere.
have @ kind of standard functions there
are, make qualified guess in of header files
pi might defined , locate file.


exercise 2
==========

2147483647 prime number ?

write program asks enter integer number
, prints 'prime number' screen if the
number prime number , 'not prime number' if it
not. program may simple, algorithm does
not have smart, must use function
int prime(int number) returns 1 if number is
prime number , 0 if not. use properly
edited version of provided 'makefile' compile
program. test program couple of
small numbers (e.g. 1 20), the
question beginning:

so, 2147483647 prime number ?




on exercise 1 used

locate glibc
less /usr/share/man/man7/glibc.7.gz

within file there link http://www.gnu.org/software/libc/documentation.html .
followed link , searched through turned dead end, have no subsequent ideas on how complete this.

supplied make file,

#-----------------------------------------------#
# makefile unix systems #
# using gnu c compiler #
# #
# adapt replacing 'program' #
# name of source code #
#-----------------------------------------------#
cc=gcc
cflags=-g -wall -d__use_fixed_prototypes__ -ansi
#
# compiler flags:
# -g -- enable debugging
# -wall -- turn on warnings
# -d__use_fixed_prototypes__
# -- force compiler use correct headers
# -ansi -- don't use gnu extensions. stick ansi c.

high: high.c
$(cc) $(cflags) -o high high.c

clean:
rm -f high



attempt @ solving problem,

/* iain taylor: prime number calculator*/
#include <stdio.h>
#include <stdlib.h>

float test_number[10];
float denom1;
int main() {
(denom1=2.0);
printf("enter value tested.\n");
scanf(test_number, sizeof(test_number), stdin);
sscanf("%d", &test_number);
while (1)
(denom1<=test_number);/* stop once test_number , denomonator equal */
{
while (0) {
(test_number/denom1==%d);/* while test_number/denom1 not intiger increment denomonator (denom1) */
denom1++;
printf("%d prime number.\n",denom1);
else
printf("%d \n",test_number);
}
}

end lot of bugs , can't figure out how fix them.

linux question,

write script checks .bak (backup) file every .data file in current
directory (i.e. every xxx.data file there should xxx.data.bak file).
script should report if there missing .bak , create one. run script in the
data directory check works.

attempt,

#!/bin/bash

a=*.data
b=$a.bak

$a in *

if
[ -e $a ]; then
[ -e $b ];
else
echo "$b missing creating now"
touch $b
fi
done
exit

inevitably going own homework, outwith understanding of course , need progress.
have go lectures @ 1pm gmt.

i know nothing c, googling know

https://www.gnu.org/software/libc/ma...constants.html

thats question 1

surely can find others following rule ( you're not first student fighting such question)


Forum The Ubuntu Forum Community Ubuntu Official Flavours Support General Help [ubuntu] Need help with linux/C


Ubuntu

Comments

Popular posts from this blog

Could not place because the source rectangle is empty

Thread: Using smartcard reader with vpnc

Adobe Font Folio 7.0 or just 7?