27/02/2023

C Program to Read Integer and Print First Three Powers (N^1, N^2, N^3)

Write A C Program To Read Integer (N) And Print the First Three Powers (N^1, N^2, N^3). For example, If the user Enters a 5 From the Keyboard Then the Output Should be 5, 25, 125 Means the power of a number is 1, 2, 3. Power in C language.

Flipkart announced the year-end stock clearance sale and as a part of they have also conducted a contest the users answering the questions asked in the contest can win moto one power free of cost. the task is to display the first three powers (n1, n2, n3) of the given number. Nishant was looking to buy moto one power. if you help Nishant in solving the task he will get his favourite mobile. Can you help him?

Logic: For this problem, We Need to multiply Numbers or we can use the power function for that take an example to better understand this problem take a Number 5 as input and multiply with the same number again like 5*5 for cube we need to again multiply with a same number like 5*5*5 or we can use the power function

Power Function Syntax;- for given example xy.

pow(x,y) also, define the datatype of x and y.

See Also: C++ Program To Read Integer (N) And Print First Three Powers (N^1, N^2, N^3)

Method 1: First Three Powers (N^1, N^2, N^3) Without Using Power Function


#include <stdio.h>
#include <math.h>

int main()
{
	/*Program By Ghanendra Yadav
	  Visit http://www.programmingwithbasics.com/
	  */
	int num;
	printf("\nEnter The Number .\n");
	scanf("%d", &num);
	printf("\nOutput Is\n\n");
	printf("%d  ,%d  ,%d \n\n", num, num *num, num *num *num);
	return 0;
}

Method 2: Print First Three Powers (N^1, N^2, N^3) Using the Power Function


#include <stdio.h>
#include <math.h>

int main()
{
	/*Program By Ghanendra Yadav
	  Visit http://www.programmingwithbasics.com/
	  */
	int num, a, b, c;
	printf("\nEnter The Number .\n");
	scanf("%d", &num);
	a = pow(num, 1);
	b = pow(num, 2);
	c = pow(num, 3);
	printf("\nOutput Is\n\n");
	printf("%d  ,%d  ,%d \n\n", a, b, c);
	return 0;
}

See Also: Java Program To Read Integer (N) And Print First Three Powers (N^1, N^2, N^3)

The Output of Power in C Language


The Output of Power in C Language

Power in C of First Three Powers (N^1, N^2, N^3)


Power in C of First Three Powers (N^1, N^2, N^3)

Similar to Power in C


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

2 comments:

  1. #include
    int main()
    {
    int num,a,b,c;
    printf("\nEnter The Number .\n");
    scanf("%d",&num);
    a= num;
    b=num*a;
    c=b*num;
    printf("\nOutput Is\n\n");
    printf("%d ,%d ,%d \n\n",a,b,c);
    return 0;
    }

    ReplyDelete
  2. #include
    #include
    int main(void)
    {
    int integer,number,i;

    printf("Enter the integer:");
    scanf("%d" , &integer);

    for(i=1;i<=3;i++)
    {
    number=pow(integer,i);

    printf("Entered integer %d 's %d power is:%d\n", integer,i,number);
    }


    return 0;
    }

    ReplyDelete