Syntax in Square of a number using C++

Posted on 7:13 PM by Azailg

    Below is the codes of square of a number program using C++ Programming Language.
    The algorithm is so simply and easy to understand. As we all know, the basic formula in square is n^2 or simple n*n. I just use the switch function, if you want to try it again by pressing "y". This one of the basic example in practicing C++ programming language.


#include < stdio.h >
main()
{
int a,b;
char choice;
start:
printf("Enter a number to be square: ");
scanf("%d",&a);
b=a*a;
printf("the square of %d is %d\n",a,b);
printf("Do you want to try it again? (y/n)\n");
scanf("%s",&choice);
if(choice=='y')
goto start;
else
return 0;
}


0 comments:

Post a Comment