[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:


need a program taht does these
thanks guys

have 3 user defined routines: sqrnum, readnum, prompt
Ï prompt: will print the prompt Enter a number
Ï readnum: will input a decimal integer from the user
Ï sqrnum: will square the number and print the square of the number as a result
Ï the main function will contain a for loop to:
Ë request input by calling prompt
Ë obtain input by calling readnum
Ë if the number is not zero, it will print the result by calling sqrnum
Ë the program will terminate when zero is entered
Run the program and input 3 different numbers. Then enter zero to exit the program.
1 Solution
tsburtAuthor Commented:
i don't know how to start this one...........any main points here?
Just somethign to get you go

void prompt(void) {
   printf("Enter a number: ");

for readnum you probably like to use
scanf or fgets + sscanf
It seems it should have a return value of float so the prototype is:
float readnum(void) {
     float result;
     /* make good use of fgets + sscanf or scanf */

the prototyp of sqrnum will be
float sqrnum(float sqrnum)
    /* implement the function */

main is always

int main(void) {
    float some_value;
    float some_value_squared;
    /* the loop  will be something like */

    do {
        some_value = read_num;
        if (is_valid(some_value)) { /* is_valid has to be provided by you e.g test on 0.0 or the like */
            some_value_squared = ...
   while (is_valid(some_value));

 return 0;

This should give you a good start ....


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now