Search C Program | nimishsoft@gmail.com

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;
}

4 comments:

  1. Dear admin if u explain every program step by step ....this will be very helpfull for us.... plz do this if u can

    ReplyDelete
  2. At least give the output of these

    ReplyDelete
    Replies
    1. Enter value of a:2
      Enter value of b:4
      Power :16

      Delete