Power

Power

Welcome to the World of Online Learning:

Hello Friends “This blog helps you to learn C programming concepts. You can learn C language at your own speed and time. One can learn concepts of C language by practicing various programs given on various pages of this blog. Enjoy the power of Self-learning using the Internet.”

Power
Power

Write a C program to Power

PROGRAM: Power

/* calculate power using while loop */
#include<stdio.h>
int main()
{
    int a, b, i, p;
    printf("Enter value of a: ");
    scanf("%d",&a);
    printf("Enter value of b: ");
    scanf("%d",&b);   
    p=1;
    i=1;
    while(i<=b)
    {
        p = p * a;
        i++;
    }
    printf("Power : %d",p);
 return 0;
}

-----------------------------------------------------

/* Calculate power using for loop */
#include<stdio.h>
int main()
{
    int a, b, i, p;
    printf("Enter value of a: ");
    scanf("%d",&a);
    printf("Enter value of b: ");
    scanf("%d",&b);   
    p=1;
    for(i=1;i<=b;i++)
        p = p * a;
    printf("Power : %d",p);
 return 0;
}

Leave a Reply

Your email address will not be published. Required fields are marked *