Use for loop only to control the console number reading logic - C Statement

C examples for Statement:for

Description

Use for loop only to control the console number reading logic

Demo Code

#include <stdio.h>

int sqrnum(int num);
int readnum(void);
int prompt(void);

int main(void)
{
   int t;/*from   w  w w .  ja  v  a 2s.  co  m*/

   for (prompt(); t = readnum(); prompt())
      sqrnum(t);

   return 0;
}

int prompt(void)
{
   printf("Enter a number: ");
   return 0;
}

int readnum(void)
{
   int t;

   scanf("%d", &t);
   return t;
}

int sqrnum(int num)
{
   printf("%d\n", num*num);
   return num*num;
}

Result


Related Tutorials