Sunday, August 2, 2009

I'm having trouble in running the user defined function in C programming?

I can printf for 0 to 9 but not %26gt; 9


#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;math.h%26gt;





int main(void)


{ int input, sum=0, product=1;


void spdigit(int, int*, int*);





printf("If number = ");


scanf("%d", %26amp;input);





spdigit(input, %26amp;sum, %26amp;product);


printf("SDIGIT = %d\n", sum);


printf("PDIGIT = %d\n", product);





return 0;


}





void spdigit(int input3f, int *sumf, int *productf)


{ int noofdigits, counter=0, i;





do


{counter++;


noofdigits = input3f/10;


} while ( noofdigits != 0 );





int remainder1[counter], remainder2[counter];





remainder1[0] = input3f%10;


remainder2[0] = remainder1[0];





for ( i=1; i%26lt;counter; i++ )


{ remainder1[i] = input3f%(10*i);


remainder2[i] = remainder1[i]; }





*sumf+=remainder1[0];


*productf*=remainder1[0];





for ( i=1; i%26lt;counter; i++ )


{ remainder2[i]-= remainder1[i-1];


remainder2[i]/= 10*i;


*sumf+=remainder2[i];


*productf*=remainder2[i]; }


}

I'm having trouble in running the user defined function in C programming?
The corrected %26amp; tested (for several times) code is--------------------------------------...

















#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;math.h%26gt;





void spdigit(int input3f, int *sumf, int *productf)


{


int noofdigits,b=1,counter=0, i=input3f;


int *rem1;


do


{


counter++;


noofdigits = i/10;


i=i/10;


}


while ( noofdigits != 0 );


i=0;


rem1=(int *)malloc(sizeof(int)*counter);


*(rem1+0) = input3f%10;


b=input3f;


for (i=1; i%26lt;counter; i++ )


{


b=b/10;


*(rem1+i)=b%10;


printf("\n%d",*(rem1+1));


}


*sumf+=*(rem1+0);


*productf*=*(rem1+0);


for ( i=1; i%26lt;counter; i++ )


{


*sumf+=*(rem1+i);


*productf*=*(rem1+i);


}


}

















Corrections are:-%26gt;


1. you can use malloc for dynamic memory allocation.


2. It is not necessary to use remainder2


instead I have used variable b whose value is inpower of 10 %26amp; which divides the total value each time by 10 so that eliminiting last digit. All Digits are stored in array pointed by rem1.











Thank you.





Mandar Gurav


Walchand College of Engineering,


Sangli,


Maharashtra,


India.
Reply:All of your printf function calls look good, so my guess is that the problem is in the spdigit function. Use a debugger to make sure that spdigit is doing what you want/expect/need it to do.





You could try this to test your printf for multi-digit output if you really want to:





int x = 1234;


printf("%d\n", x);
Reply:Your do while loop is faulty

garland flower

How do I return a 2D array from a function in C?

do i need to use pointers/struct in order to make it easier? If possible, a straightforward and simple way would do... thanks!

How do I return a 2D array from a function in C?
You cannot pass an array to a function by value. A pointer is always passed. You can get the same result as pass-by-value by declaring the array as const. Then the called function cannot change any values in the array.





A contrived by hopefully instructive example.





#include %26lt;stdio.h%26gt;








void cannotChange1(const int arr[], const int size)


{


int i;





for (i = 0; i %26lt; size; ++i)


{


printf("%d\t", arr[i]);


}





printf("\n");


}








void cannotChange2(const int *arr, const int size)


{


int i;





for (i = 0; i %26lt; size; ++i)


{


printf("%d\t", arr[i]);


}





printf("\n");


}








void canChange1(int arr[], const int size)


{


int i;





for (i = 0; i %26lt; size; ++i)


{


arr[i] = arr[i] * 2;


printf("%d\t", arr[i]);


}





printf("\n");


}





void canChange2(int *arr, const int size)


{


int i;





for (i = 0; i %26lt; size; ++i)


{


arr[i] = arr[i] * 2;


printf("%d\t", arr[i]);


}





printf("\n");


}








int* viaReturn(int *arr, const int size)


{


int i;





for (i = 0; i %26lt; size; ++i)


{


arr[i] = arr[i] * 2;


printf("%d\t", arr[i]);


}





printf("\n");








return(arr);


}








int main(int, char **)


{


int a[3] = {1, 2, 3};


int *b;





cannotChange1(a, sizeof(a) / sizeof(int));


cannotChange2(a, sizeof(a) / sizeof(int));





canChange1(a, sizeof(a) / sizeof(int));


canChange2(a, sizeof(a) / sizeof(int));





b = viaReturn(a, sizeof(a) / sizeof(int));





int i;





for (i = 0; i %26lt; sizeof(a) / sizeof(int); ++i)


{


printf("%d\t", b[i]);


}





printf("\n");


}
Reply:You can always create the 2D array off the heap and then pass the address back to the caller and then have the caller use it for whatever but not to forget to free the space when you are done...





Another alternative is to pass in the 2D array as a parameter into the function (by reference) and then filll it and then just leave the function which would maintain the array's content.





You mentioned you are using "C" and not C++ so unfortunately you dont have the luxury of alias nor the new/delete keywords....





I hope i didn't confuse you....because i am not sure you level of what i am talking about maybe i should explain s'more?





It's been a while since i've looked at C but for your 2D array you can pass it back by allocating memory off the systems heap space by using malloc(..) ... my appologies if C uses a different function for this....it's been a while....C++ is more elegant....so in this example:





int *my2DArray;


malloc(my2DArray,sizeof(int)*10);





This will create a 2D Array that can hold 10 integer values.





so here is what your function would look like:





int* MyFunction(void)


{


int *my2DArray = NULL;


malloc(my2DArray,sizeof(int)*10);





/* Do stuff Here */





return my2DArray;


}








void main()


{


int *myArray=NULL;


myArray = MyFunction();





/* Do whatever here */





free(myArray);





}


What is the difference between a method an d function in c++?

the major difference between method and function is





Function have the return value.





In Method there is no return Value.

What is the difference between a method an d function in c++?
A procedure is a sequence of zero of more statements combined under one common name.





A function is a procedure that returns a value.





A method is a procedure or function that is part of a class; sometimes it's also referred to as member function. Which term is used depends largely on the programming language that the speaker is used to.





Note that lots of people, even the ones who are aware of the above distinctions, use the terms procedure and function interchangeably.


How do you pick up a baby and normally function after C-section?

I am 27 weeks and hope I don't need one, but from those with experience - did it hinder getting close to, picking up, nursing baby, etc?

How do you pick up a baby and normally function after C-section?
It is a little more uncomfortable, but it is still possible to do all the things your new baby will need. Hopefully you have someone to help you for the first few days or so.
Reply:i had two c sections on i'm 28 weeks about to have another section. What helped me the most was my husband, i would not have been able to do it without him, When i need to nurse my husband would bring the baby to me, but after about a week i was able to do most of it on my own.
Reply:Having a c-section does not keep you from holding or nursing your baby. You will be sore from the c-section and need help caring for it due to the fact that you can't be as mobile or do lots of movement because you are healing from major surgery. I have had 2 c-sections and 1 vaginal birth. The difference between the births for me was that I needed more healing time and rest with the c-sections. But, you can still nurse and hold your baby...but, may need help picking your baby up for a few days.
Reply:Nope doesnt hinder a thing...just recovery process is slower, you move around slower, you will need a pillow for nursing, etc..but you still pick up the baby the same way anyone else would.
Reply:some people say you move around slower, but I have to disagree. Ihad to 2 naturally and my last one was c-section. I thought that the c-section was much easier than the vaginal deliveries, because with my 2 other children I had to have an episiotomy and I think you move around much slower and the clean up is a bigger pain in the butt
Reply:no you can still hold the baby and feed it and change it and stuff it just takes a little longer to get up and down and its hard to stand for a long period of time so you learn to do things quick and you learn how to do things like a change him/her while you are sitting. But after about a week or two it startes to get better. I have had 2 c-sections and i did everything by myself for both. tyr not to take the pain meds unless someone is around to help you if you get dizzy or sleepy and if you are alone ask your doc for a lower dose prescription or for something that wont make you tired. Oh yeah wether you take meds or not you are gonna be really tired its nice to have someone there so you can nap but if not you will live. that goes away after about 2 weeks too. Good luck and Congrats


C++ reading from file into array using a function?

text file contains title of store then a product code, product name, then product price. so type string, string, long respectively. program compiles and runs fine until count is returned in main. something is wrong with the loop and i don't know what. this is the important stuff:


--------------------------- function: ----------------------------


long readFile (string code[], string product[], long price[])


{


const long ITEMS = 24;


string temp,


store;


long count;


ifstream fin ("program5.txt");





getline(fin,store);


count=0;


fin%26gt;%26gt;temp;





while (!fin.eof())


{


temp=code[count];


getline(fin,product[count]);


fin%26gt;%26gt;price[count];





count++;


fin%26gt;%26gt;temp;


}


fin.close();


return count;


}


----------------from main:-----------------


.......


count=readFile(code,product,price);


fout%26lt;%26lt;count%26lt;%26lt;endl;





for (pos=0; pos%26lt;count; pos++)


{


fout%26lt;%26lt;code[pos]%26lt;%26lt;endl;


fout%26lt;%26lt;product[pos]%26lt;%26lt;endl;


fout%26lt;%26lt;price[pos]%26lt;%26lt;endl;


}


....





if more info is needed i can provide it. reminder this is c++

C++ reading from file into array using a function?
count looks ok--not sure why count is giving you a problem.





Look at the line just following the while declaration. You have the left side and right side inverted. Use:





code[count] = temp;

blazing star

How can we pass a multidimensional array to a function in C?

You pass a pointer to it.


void doStuff(char **pJunk) {


...


}





int main(int argc, char *argv[]) {


char junk[3][4];





... fill it in





doStuff(junk);





}

How can we pass a multidimensional array to a function in C?
Toadaly's solution doesn't tell how the function would know the array's dimensions...
Reply:#define COLUMN 3





void Dump(int buffer[][COLUMN])


{


for(int row=0; row %26lt; 5; row++)


for(col = 0; col %26lt; COLUMN; col++)


printf ("row: %d\tcol: %d\t%d\n", x, y, buffer[row][col]);


}





int main()


{


int g[5][COLUMN];





/* fill g up */





Dump(g);





return(1);


}


Suppose that the cost function for a product is given by C(x) =.002^3 -9x + 4000.?

Suppose that the cost function for a product is given by C(x) =.002^3 -9x + 4000.


Find the production level that will produce the minimum average cost per unit.





If you could show your work so I can get a better understanding of this problem it would help me.

Suppose that the cost function for a product is given by C(x) =.002^3 -9x + 4000.?
average cost: A(x) = C(x)/x.





minimum: A'(x) = [xC'(x) - C(x)] / x^2 = 0





then xC'(x) - C(x) = 0


C'(x) = C(x)/x


it occurs when the marginal cost equals the average cost.


solve for x .... x is the desired production level.


There is a problem with your function... it is not expressed properly... §





It is better to solve the equation: xC'(x) = C(x)


x *(.006x^2 - 9) = .002x^3 -9x + 4000





anyway... i believe its at x = 100.


Does anyone know how to make a stopwatch function in C++ (emacs) that runs on a Unix OS?

I tried using sys/time.h but it says the file is not found and I usually don't program on Unix at all but it is required for a class and I have no idea what to do.





I also need to make the timer start when the user presses a key.

Does anyone know how to make a stopwatch function in C++ (emacs) that runs on a Unix OS?
At the link is a simple timer example.


How do you take the sin of a function in c++?

I am trying to perform sin(pi*0.5), but I cant get it to work. Here is my code:


#include%26lt;iostream%26gt;


#include%26lt;math.h%26gt;


using namespace std;


const double PI = 4.0*atan(1.0)


int main()


{


x = sin( pi*0.5 );


cout %26lt;%26lt; x;


}


It will not give the correct answer. Any help?

How do you take the sin of a function in c++?
error 1 -- x should be declared like





double x;





error 2 -- there is a ; at the end of const double ...





error 3 -- the const is PI all caps.





It works on my machine.

imperial

Consider a three-state model for Helix-coil transition h, c, and i write expression for partition function?

Consider a three-state model for Helix-coil transition h:helix,coil:c, and intermediate:i. Assume the model is non-cooperative. write expression for partition function of such a chain.

Consider a three-state model for Helix-coil transition h, c, and i write expression for partition function?
h= (C*I/A+T/k)*z*log(.7*y)
Reply:h= (C*I/A+T/k)(.7*y)


How do you return a pointer from a function in c++?

Just assign the desired variable to the pointer that was used in the function.

How do you return a pointer from a function in c++?
int* func1()


{


int* a;


return a;


}


List all possible ways to program the NOT function in C++.?

If you mean binary negation "~", then you can use:


~x = x ^ 0xFFFFFFFF (or however many bits your complier uses)


~x = -x - 1


or you could use a really big lookup table with every possible value in it (not very efficient)

List all possible ways to program the NOT function in C++.?
simple macro:


#define NOT(expresion) (!expresion)





or simple function:


int NOT(int expresion)


{


return !expresion;


}





example:


int b;


b = NOT(5 %26lt; 0);


/* value of b = true */


b = NOT(true);


/* value of b = false */
Reply:Well NOT is taking the Opposite. so if you created a function with 1 parameter (the variable that is being "NOT"ed) use the - (negative) sign. it work work.





NOT true = false





That's all you are doing.





Hope that helps.


If a competitive firm has a total cost function of C=450+15q+2q^2 q=25 and price=115 how do i find the profit?

Profit = total price - total cost


so start by working out Total Cost





Total Cost = 450 + 15q + 2q^2, where q=25


= 450 + 15*25 + 2*(25^2)


= 450 + 15* 25 + 2*625


= 450 + 375 + 1250


= 2075





Total price = unit price * quantity


= 115 * 25


= 2875





Therefore,





Profit = 2875 - 2075 = 800

If a competitive firm has a total cost function of C=450+15q+2q^2 q=25 and price=115 how do i find the profit?
calculte the cost by puting 25 in for q, then profit =(price-cost)q

elephant ear

What is the correct form of the main function in C if i expect command line arguments?

Is it like this?


int main(int argc, char *argv[])


And if the first argument represents the filename (and location), then argc counts all arguments, or just those except the first one. In other words, a program with no extra arguments would have argc==1?

What is the correct form of the main function in C if i expect command line arguments?
You have two synthaxes :


1) int main(int argc, char *argv[]);


and


2) int main(int argc, char **argv);





When a program starts, the arguments to main will have been initialized to meet the following conditions:





- argc is greater than zero.


- argv[argc] is a null pointer.


- argv[0] through to argv[argc-1] are pointers to strings whose meaning will be determined by the program.


- argv[0] will be a string containing the program's name or a null string if that is not available. Remaining elements of argv represent the arguments supplied to the program. In cases where there is only support for single-case characters, the contents of these strings will be supplied to the program in lower-case.





To illustrate these points, here is a simple program which writes the arguments supplied to main on the program's standard output.





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





int main(int argc, char **argv)


{


while(argc--)


printf("%s\n", *argv++);


exit(EXIT_SUCCESS);


}
Reply:yes, a program with no extra argu have argc==1.


Give me some details of non-recursive function in 'c' programming language to reverse a doubly linked list.

node.next -%26gt; node.next.next = my head will explode


How am i using this exp() math function wrong? C++ programming?

float newBalance = principal * ( 1 + interestRate )exp( years );





im trying to make it (1 + interestRate ) to the power of years.





Any insight would help.





Thanks

How am i using this exp() math function wrong? C++ programming?
There are a couple things wrong with your statement. First, you need to look up exp() and see what it does. It doesn't do what you think it does. Second, exp() is a function, not an operator, so you can't just stick it between two parenthesized expressions.





What you want is pow(). pow(1 + interestRate, years) will do what you want.
Reply:Syntax for exp() function is given below:





double exp ( double x );


float exp ( float x );


long double exp ( long double x );





I believe what you are trying to do is new balance = principal x (1 + interestRate) x exp(years)





for this use





float newBalance = principal * ( 1 + interestRate )*exp( years );





As (1 + interestRate)exp(years) is syntactically wrong... because its missing * operator between ( 1 + interestRate ) and exp() function which the compiler can't interpret... So leads to syntax error


Only One program using all the string function in C Program?

Which function are you keenly looking for? If you have to use any string function in C language, you need to include the String.h header file as #include%26lt;string.h%26gt;. string.h has all the list of string functions such as strlen(), strcpy() etc. Use help function in the C editor to know the list of string functions and their usage.

lady palm

Can u explain the importance of volatile function in c program?

Nope.

Can u explain the importance of volatile function in c program?
The volatile keyword for a Storage Class modifier informs the compiler that the variable can be modified in ways unknown the the compiler. Although this is a new feature, it is not available with old compilers, the concept is not. This usually applies to the variables mapped to a particular memory address viz.,device registers.





In their cases it is important for the series of statements to be executed exactly as they are written and not reordered for optimization purposes. The best example would be the keyboard where you read the character from the keyboard and store it to a corresponding variable.


Ex:


void get_keyboard()


{


extern char KEYBOARD;


char c0,c1;





c0=KEYBOARD;


c1=KEYBOARD;


}





Here you store 2 values to c0 and c1 using the same variable KEYBOARD,which means the variable KEYBOARD holds different values to be stored at c0 and c1 seperately. However the compiler unaware of this fact will store the KEYBOARD value in a register and then store it to c0 and c1 resulting the same value to be assigned to both c0 and c1. So in order to get it goin to ensure the KEYBOARD is read twice you declare it volatile.





extern volatile char KEYBOARD;





This should answer your question i guess!


Can u explain the importance of volatile function in c program?

http://gcc.gnu.org/onlinedocs/gcc-3.0.4/...


How to find address of an overloaded function in C++?

the address in memory? yuck!





You could play address math in c, but it is distasteful in higher level languages.


Give me an example of user define function in C language please?

A user defined funtion is one that has a proper signature i.e. name, return type (optional in some cases) and arguments e.g.





//function declaration, can optionally be written outside


//the 'main' function


bool myFunction(int x, int y);





//the funtion returns true if y is divisible by x,


//otherwise it returns false


bool myFunction(int x, int y)


{


if(x%y == 0)


return true;


else


return false;


}

snow of june

Function calling array C++?

Hi, I'm stuck on a problem I'm doing, I was wondering if someone could help. I need to create 3 functions


1. Max temp


2. Min temp


3. Average temp





An array will be populated with the appropriate no of temps . The functions will perform the calculations and display the results to the user





How would I approach this? I'm only started to learn about arrays and am clueless really. How would I find the max and min in a function?





I would really appreciate any help you culd provide

Function calling array C++?
int fn_GetMax(int* pInput, int length)


{


int ret = -1 ;


if(pInput != 0 %26amp;%26amp; length %26gt;= 1)


{


ret = pInput[0];





for(int i=1; i%26lt;length; i++)


if(pInput[i]%26gt; ret) ret = pInput[i] ;





}





return ret;


}





int fn_GetMin(int* pInput, int length)


{


int ret = -1 ;


if(pInput != 0 %26amp;%26amp; length %26gt;= 1)


{


ret = pInput[0];





for(int i=1; i%26lt;length; i++)


if(pInput[i]%26lt; ret) ret = pInput[i] ;





}





return ret;


}





int fn_GetAvr(int* pInput, int length)


{


if(pInput == 0 || length %26lt;= 0)


return 0;


int sum = 0 ;


for(int i=0; i%26lt;length; i++)


sum+= pInput[i];





return sum/length;


}





______________________________________...





good luck
Reply:Well, with out giving it completely away in code:





Draw it out on a sheet of paper, use an array with 5 elements as an example. Make up some temps {32,-4,78,55,77}.





Now, imagine you can't see the array, except for the first element. How would you go through the entire array and determine the maximum temp (the highest number) or the minimum temp (lowest number)?





Basically, you want to compare each number until you find the largest or smallest. Just start with the first element: for maximum: if the first number (current) is smaller than the next, then next becomes the current and compare it to the next number. If the next number is smaller than current, then keep the current number as current. For smaller, reverse the logic.





Average, well, you know what that is, add it all up and divide by the number of elements.
Reply:For the minimum and maximum, "guess" a minimum and maximum as some element of the array. Then, loop through the array, and if you find anything greater than your current guess for the maximum or anything smaller than your current guess for the minimum, then update your guess appropriately. When you are done, the guess for the minimum/maximum will be the actual minimum and maximum values. For the mean, simply sum all the elements and then divide by the number of elements, the same as you would by hand.


What does 'f' represent in "printf" function in C language?

why they used printf instead of print?

What does 'f' represent in "printf" function in C language?
The class of printf functions stands for "print formatted" :)
Reply:print formated.....
Reply:As he said there is a family of functions used for formatted output! printf, fprintf, sprintf, etc!





Don't ask me why they made so many! Ask Dennis Ritchie! printf prints to the standard output so it is the most common one!





I even like printf...print is just too common! printf is original...it is elite :p
Reply:Hi!! f in printf stands for format or formated





At first it may appear that C's basic IO functions look strange compared


to "cin" and "cout". But in fact "scanf" and "printf" are very powerful


tools. The "f" in "printf" and "scanf" stands for "formated". The first


argument to printf is always a string which defines a format. Here's an


example:





int x = 3; int y = 4;


printf("x is %d and y is %d",x,y);


What is the use of malloc() function in C?

malloc is used to allocate memory from the heap. for example if you want an array of fifty integers:





int * array50 =(int *) malloc(50 * sizeof(int));





then you can use it as an array as long as you need it. for example:


array50[3] = 4; //assigns element 3 just like a static array.





the idea is that if your program only allocates memory while you need it you are free to use lots more memory instead of tying it up loads of memory with static declarations.








when you are done you use free


free(arrray50);

What is the use of malloc() function in C?
Since memory in a computer is a shared resource, when you need to use memory to store some data the program has to ask for memory, so the operating system can assign to your program certain segment of tha RAM memory.


Example:


malloc (30)


will assign to your process 30 bytes of memory. The operating system knows where in the memory is that segment, you only get a pointer to that address.





To ask for space for 50 integers:





int * a = (int *) malloc (sizeof(int) * 50);





and so on...


Bye.
Reply:malloc() allocates a block of memory on the heap and returns a pointer to the block.





When you use malloc(), you must later use free() to de-allocate the memory when it's no longer needed.





See http://en.wikipedia.org/wiki/Malloc


I need to create a random function in c++ using this formula =f(x) × 100 , f(x) = (pi + x)^5?

i need the help fast plz

I need to create a random function in c++ using this formula =f(x) × 100 , f(x) = (pi + x)^5?
I can give you video tutorial on how to use the rand() function:





http://xoax.net/comp/cpp/console/Lesson2...





I hope that helps. Could you give some clarification?
Reply:I shall give you some quick and dirty code which implements the formulae you have given me. It is random in the sense that anything I do is random and unfocused when it's quick and dirty. Its output is not random because it always seems to return 1. Obviously, you'll have to debug it yourself (but this sounds like homework so you should anyhow) and this may help anyhow.





#include %26lt;iostream%26gt;


#include %26lt;cmath%26gt;





using namespace std;





float funky(float );





int main()


{





double x, Rand;


int i;





cout %26lt;%26lt; "Enter a number:";


cin %26gt;%26gt; i;





x=(double) i;





Rand=funky(x)*100.0;





cout %26lt;%26lt; rand;


return 0;


}





float funky(float x)


{


double pi=3.14159;


double temp1, temp;


temp=(pi*x);


temp1=pow(temp,5);


return temp1;


}

sweet pea

How do i calculate the cost function for c(x) = 7000 + 2x ?

I think this is the cost function. If you want the marginal cost, it's c'(x) = 2

How do i calculate the cost function for c(x) = 7000 + 2x ?
That is the cost function.


Can we use main before include function in c++ ?

This is not a very well worded question, but I think you are asking "Can main come before #includes". If so, yes, includes can come along anywhere in C++.

Can we use main before include function in c++ ?
#include %26lt; %26gt;


Void , int , .... main()


{


....





return 0 ;


}


Void , int ,.... function1 (..... , .... , ...)


{





....


}


This code is correct ....


If you meant to ask for that answer ....

bottle palm

In a competitive market with a total cost function of C(q)=4q^2 + 16 and the marginal cost function MC(q)=8q?

need variable cost, fixed cost, AC, AVC,AFC

In a competitive market with a total cost function of C(q)=4q^2 + 16 and the marginal cost function MC(q)=8q?
4Q, man, 4Q


What is a formal name for function declaration ? (C++)?

thank you

What is a formal name for function declaration ? (C++)?
c represent the letter C.


because there was languages before "C" named "A" %26amp; "B" then our "C".


And "++" coz there is an operator in the "C" called "++" not found in other languages.


Function declaration:





returnValue functionName(parameters);
Reply:Not sure, but, The Declaration?


How can I write a function in C++ and win32 that draws a cube?

this is my assignment and need to do it asap!

How can I write a function in C++ and win32 that draws a cube?
i am not sure of the function, i would go to


http://www.planet-source-code.com/ and take a look at sample codes, i have used this side for code.


Can u help with "srand" function in c...please?

ok my program is to produce any integer between 60 to 180.lets say X. then again i need to produce any integer wich should be between square root of X and square root of X+20. my program is like this:





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;math.h%26gt;


#define low_d 60


#define high_d 120


#define G 9.8


int


main(void)





{





double i, seed ;


double A, low_v, high_v,randomd ;





srand(time(0));








randomd = low_d + rand() % (high_d + 1 - low_d);


printf("\n%f\n ", randomd) ;








A = randomd * G;


printf("%f",A);





low_v = sqrt(A);


high_v = sqrt(A)+20;








srand(time(0));


printf("speed = %f",rand() % high_v + low_v);

















return(0) ;


}














so the prob is that it produces only integers as a random numbers. but i need real numbers. so when i use double and %f or %.2f it shows error " invalid operands to binary %"





any ideas??

Can u help with "srand" function in c...please?
I just did a complete search on my computer for "s rand srand" s r a n d, hidden or not, and found nothing relating to your computer problem. Sorry, I can not help you with your problem. Be aware that changing Windows functions or other settings, hidden or not, can be detremental to your computer, possibly only fixable by a computer programer that charges a lot of money.

magnolia

How can CONVERSION STRING to FUNCTION in C?for example "f(x)=sin(x=3)+x?

you can't just do it.





compare the string to "sin" and then call the sin function





if(myString == "sin")


{


sin(x);


}





you're going to have to do the processing there though. I'd say consume characters to the first open-parenthesis, and then compare it, then consume what's inside the parenthesis.

How can CONVERSION STRING to FUNCTION in C?for example "f(x)=sin(x=3)+x?
The link below will get you close although it is in C#. Can't remember if C has an Eval function but the gyst is to take any string and break it down into its parts character by character. You will have to extract the variables (x in your case) and you will need to ask the caller what is the value for x. Not sure this is what you are looking for.





The other thought is to offer a function f that takes a value (x) and returns sin(x) and if no value is passed, the I guess you default x to be 3.
Reply:From the little information you gave, I can guess that you want the user to input some function as a string, and then make that as a function within the program dynamically. Well it is possible, but it is a very lengthy process, and certainly not something I would be doing now.


Need help making a power function in C using loops. This is what i got so far.?

#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





void float DP(double x, int n)


{


double x, DP;


int n;





DP=pow(x,n);


printf("%d to the %i power is %d", x, n, DP);








}








int main()


{


float x, DP;


int n;





scanf("%d%i", x, n);


DP(x, n);





printf("Answer equals %d\n", DP);





return 0;


}

Need help making a power function in C using loops. This is what i got so far.?
double DP(double x, int n)


{


double result = x;





for(int i = 1; i %26lt; n; i++)


{


result *= x;


}





return(result);


}
Reply:Oops, misread what you said in my first response -- you said you need to use loops. Very well:





double DP(double x, int n) {





double result = 1.0;


for(int i = 0; i %26lt; n; i++) {


result *= x;


}





printf("%f to the %d power = %f\n", x,n,result);





return result;


}


Lcm gcd program with recursive function in c language?

Hi I'm not exactly remembering the algorithm. I think its like this.





int gcd(int a, int b)


{


int g;


if(b==0)


g=a; //if b=0 then gcd will be a


else


{


if(b%26gt;a)


swap(a,b);


else


a=a%b;


g=gcd(b,a);


}


return g;


}





For example a=40 and b=16





Level 1:


a=8 b=16 // after a = a%b. Now we are calling gcd(16,8)





Level 2:


a=0 b=8 // after a = a%b. Now calling gcd(8,0)





Level 3:


Now b==0 and hence gcd will be 8.





Now you can find the lcm from the formula gcd*lcm = a*b





Yeah for lcm, lcm = (a*b)/gcd





Is it enough!


How do I save a function in C++?

I already made the code,now all I have to do is save it.


How to do it?

How do I save a function in C++?
just save the code file or compile it to a lib file. I don't understand your problem
Reply:just press, ctrl + S. nothing else!
Reply:You can save a function in separet Header File.... Then include this file in your code to call this function again and again.

forsythia

What is the most important function in C++?

thanx for help

What is the most important function in C++?
the "main" function. without it you wouldnt have a program!!
Reply:Kind of a silly question, I guess the pointer operator (*). Without it, C++ would be a lot different and a lot less performance friendly.
Reply:Each an every function is important. U cant say which is important. Its not an exam, to tel that this and that are important. Functions are used to use it whereever it is required.


I can say in development(IT industry), uses String functions and date function. Any one who is well versed in these two in any language can shine well. I mean to say his/her job will be easy
Reply:Your best functions/methods are the ones you declare yourself. They are the ones that end up doing the things that required you to write a program in the first place.





-BoneSaw


We dont use & in scanf function in c for reading strings .y is it so?

Bcoz, the char itself returns the address...


so no need for using '%26amp;' before it...

We dont use %26amp; in scanf function in c for reading strings .y is it so?
yeah! we don't use scanf ,instead we use 'gets' %26amp; for printing a string we use 'puts'. this is b'coz scanf won't take spaces in between words,but using gets would avoid this problem.
Reply:Yes buddy,





take the below eg.





int number;


char name[10];





when ever you specify the name of a integer variable, i.e number, you are indicating just the content of the variable. If you get a input for that variable, you have to store that input in the memory location. so when put %26amp; before the variable name, ie. %26amp;number, now you are indicating the memory location of that integer, where you are going to store the input.





But in the case of string, whenever you specify the name of the variable, you are directly indicating the base address of that string. i,e by giving just name with out %26amp;, you specify the start address of the memory location from where you have store the input.





. . .


How can i call javascript function in c# web based?

You can't directly call into a Javascript function, but you may:


1) create a client side script from the server side (a page that outputs %26lt;script%26gt;alert('some message')%26lt;/script%26gt; for instance)


2) there's some new support in Asp.NET 2.0 for client to server interaction (AJAX)


3) you may look for ATLAS which is a foundation just for that kind of things (Web 2.0 in general)


Is there a text formatting function in C++?

Something like


format("Integer %i \n String %s",integer,string);


???

Is there a text formatting function in C++?
No, not in standard C++. As you indicated, printf() is still available to C++ as a library function. However, you stated that you're not interested in printf().





cout/ofstream and manipulators are considered far superior to the C standard library in most respects. Internally, the C++ implementation of stream I/O is much more efficient and the syntax can be considered more natural to code in many situations. For instance, cout statements don't need to be parsed at runtime unlike a printf() format string.





Also, printf() is not object-oriented so it is still around for backward compatibility but is not the preferred C++ output mechanism. With C++ stream I/O, you can actually extend %26lt;%26lt; with operator overloading to support custom output of your own classes/structures.

jasmine

Can you write a "split" function in C?

I blew an interview because I screwed up my pointer arithmetic while parsing a string:





Here is the syntax:





prompt%26gt;./split "This Is an input string" " "





output:


This


is


an


input


string





or:


prompt%26gt;./split "This is an input string" "p"


output:


this is an in


ut string





I tried putting '\0' wherever the split character occurred, but I couldn't turn it into an array of substrings.





Any ideas?

Can you write a "split" function in C?
Only strlen, strcpy, and strcat, eh? That's pretty harsh. I think you have the right idea putting '\0' at the split points. Instead of creating an array of substrings, though, create an array of pointers to the substrings.





Pseudocode:





char *s points to your input string


S is an array of pointers to char


char *p declared to walk through the input string


initialize p = s, i = 0





do {


set S[i++] = p


set p to next split point


set *p = '\0'


p = p + 1


} until last substring found





How about that? You don't even need any of those string.h functions!
Reply:And you weren't allowed to use strtok?


Write c program to delete one character from string without using string handling built in function of c?

e.g.


my string is "hello"


and i want to delete 'l'


so my abnswer will be : "heo"

Write c program to delete one character from string without using string handling built in function of c?
Here it is. Rewrite as you wish:





void Remove(char *p, char ch)


{





char *temp;


temp=p;


while (*temp!=NULL)


{


if (*temp==ch){


while (*temp!=NULL){


*temp=*(temp+1);


if (*temp!=NULL) temp++;


} /*end while*/


temp=p;


} /* end if*/


temp++;


}/*end while*/


} /*end Remove*/





EDIT: C passes everything by value (that is it creates a new variable it copies the contents of parameters into) EXCEPT arrays. It creates pointers to arrays. Thus, in this program the calling function I used is:





int main()


{


/* Declarations*/


char Array[50], ch;





printf("Enter a string:");


gets(Array);








printf("Enter a character to remove:");


ch=getc(stdin);


printf("Your string is:\n%s\n", Array);


Remove(Array, ch);


printf("Your string is:\n%s\n", Array);


return 0;


}








You can send it the name of the array or you can send it %26amp;array[0] or whatever you like.


What is a use flag() function in c language?

It is actually used to give a specific address of a variable to be called..


If f,g are analytic function on C s.t fg=0,show either f or g is 0?

Hint: If an analytic function is 0 on a set with its accumulation point, then the function is identically 0.





Now, either f or g has to have this property since at each point one or the other is 0.

crab apple

Write a C/C++ program which consists of a user-define function Prime. This function will take a number and che

Write a C/C++ program which consists of a user-define function Prime. This function will take a number and check that the number is prime or not if the number is prime Display The number is Prime other wise display The number is not PrimeCall this function in main program.

Write a C/C++ program which consists of a user-define function Prime. This function will take a number and che
#include %26lt;iostream%26gt;








// The following function works on positive numbers only


bool Prime(int number);





int main( )


{


int number = 0;


cout %26lt;%26lt; "Enter a number: ";


cin %26gt;%26gt; number;





if(Prime(number))


cout %26lt;%26lt; "The number is prime" %26lt;%26lt; endl;


else


cout %26lt;%26lt; "The number is NOT prime" %26lt;%26lt; endl;





return 0;


}





bool Prime(int number)


{


for(int i = 2; i %26lt; number - 1; i++)


{


if((number % i) == 0)


return false;


}


return true;


}
Reply:Don't post the question from your assignment to Internet; try to use your own imagination and skills you learnt from lectures; rather these assignments are brain teasers to make you ready for exams.
Reply:First thing you need to do is set a cin%26gt;%26gt; statement for the user to enter a number. Then have the an if-then statement that checks the number against the formula for determining if a number is prime (I dont remember if off the top of my head but its something like a number thats only divisable by itself). Then you can set your cout%26lt;%26lt; after the if as "The number",x,"is prime." and then for the else cout%26lt;%26lt; "The number",x,"is not prime." Should work out fine. No need to make it more complicated than it needs to be.
Reply:The code given by Silver is pretty good. I am only suggesting minor improvements to the same code








#include %26lt;iostream%26gt;








// The following function works on positive numbers only





// Haidry Comments:


// long is larger in size and hence can accommodate larger


// numbers. The prototype could be


// bool Prime(long number).


// Haidry Comments End





bool Prime(int number);


int main( )


{


int number = 0;


cout %26lt;%26lt; "Enter a number: ";


cin %26gt;%26gt; number;





// Haidry Comments:


// Use of 'abs' function can eliminate the


// problem with negative numbers. The call could be like this


// if (Prime(abs(number))


// Haidry Comments End





if(Prime(number))


cout %26lt;%26lt; "The number is prime" %26lt;%26lt; endl;


else


cout %26lt;%26lt; "The number is NOT prime" %26lt;%26lt; endl;





return 0;


}





// Haidry Comments:


// If you changed the prototype above make necessary


// change here as well


// bool Prime(long number)


// Haidry Comments End





bool Prime(int number)


{





// Haidry Comments:


// The loop does not need to run till 'number -1'. It only


// needs to check integers up to half of the 'number'. So the


// for loop could be as following


//for(int i = 2; i %26lt; number / 2; i++)


// Haidry Comments End





for(int i = 2; i %26lt; number - 1; i++)


{


if((number % i) == 0)


return false;


}


return true;


}


How to add a function in C library ?

Try and get in touch with the C standards committees. Easiest way is to post on comp.lang.c (or is it comp.std.c?). Anyway, explain your superbly amazing function, writing the implementation code, and why it should be including the standard library.





Then debate over it, trying to survive the probes of a number of other brilliant minds. Try to keep everyone convinced that your function is the next best thing, for about a decade or whenever the next standard gets released. Then, there you go ;p





Oh wait, did you intend something else? Sorry, I'm not psychic, so you may have to say something more. More = more than one vague line.

How to add a function in C library ?
Do you mean how to properly program headers?


How to use arc function in c any example??

Hold 'Alt' and Press The Tab, Swithes Between Screens...





Or you can set programes to open with Ctrl + Alt + *LETTER*


(right click an icon to set it)





Hope this helps you get the most out of your Keyboard! ^.^


If the total cost function is c(x)=1/2x^2-5x+500, find the production level that will minimize aveerage cost?

take the derivative of the function, and you get:


c'(x)=x-5





Solve the above to find where c'(x)=0, and you get x=5.





So, the solution is x=5. This is the value of x that gives the minimum cost for c(x).





Hope this helps.

strawberry