Follow This Blog For more... 😊

Program to accept a number from the user and print its square & cube.| Using C language| very Basic| C Program series 05|

 

👨‍💻Program to accept a number from the user and print its square & cube.

Code:

Way 1 :


    //Program to accept a number from the user and print its square & cube.

    #include<stdio.h>
    main()
    {
        printf("Program to accept a number from user and print its square & cube.\n");
       
        float n,square,cube;
       
        printf("Enter the number:");
       
        scanf("%f",&n);
       
        square=n*n;
        cube=n*n*n;
       
        printf("\n-->SQUARE OF %.2f IS %.2f\n",n,square);
        printf("-->CUBE OF %.2f IS %.2f\n",n,cube);
    }

 

Way 2 :

   
    //Program to accept a number from the user and print its square & cube.
   
    #include<stdio.h>
    #include<math.h>//included math.h header file to use mathematic function in code.

     main()
    {
        printf("Program to accept a number from user and print its square & cube.\n");
       
        float n,square,cube;
       
        printf("Enter the number:");
       
        scanf("%f",&n);
       
        square=pow(n,2);//Using power function from math.h header file.
        cube=pow(n,3);
       
        printf("\n-->SQUARE OF %.2f IS %.2f\n",n,square);
        printf("-->CUBE OF %.2f IS %.2f\n",n,cube);
    }
 

Output:




👉Click for more C Program series Questions.[Questions list]

Comments

Popular Posts