Calculation of A to the power of B using Functions
Write a function power(a,b), to calculate the value of a raised to b.
#include<stdio.h>
main()
{
int power (a,b);
int a, b, result;
printf("Enter the value of a and b:");
scanf ("%d %d", &a, &b);
result=power(a,b);
printf("%d raised to %d is %d", a, b, result);
}
power (int a, int b)
{
int calculation=1, calc;
for (calc=1; calc <=b; calc++)
{
calculation=calculation*a;
continue;
}
return(calculation);
}
The File can be found at:
Download File
#include<stdio.h>
main()
{
int power (a,b);
int a, b, result;
printf("Enter the value of a and b:");
scanf ("%d %d", &a, &b);
result=power(a,b);
printf("%d raised to %d is %d", a, b, result);
}
power (int a, int b)
{
int calculation=1, calc;
for (calc=1; calc <=b; calc++)
{
calculation=calculation*a;
continue;
}
return(calculation);
}
The File can be found at:
Download File
Comments
http://www.a2zhacks.blogspot.com to learn C,C++,VB programming.
#include
void roman(void);
main()
{
roman();
getch();
}
void roman()
{
int y,i;
printf("input the year to get its roman numeral:\n");
scanf("%d",&y);
for(i=1;i<=y;i++)
{if(y>=1000)
{
printf("m");
y=y-1000;}
}
for(i=1;i<=y;i++)
{if(y>=500)
{
printf("d");
y=y-500; }
}
for(i=1;i<=y;i++)
{if(y>=100)
{
printf("c");
y=y-100;}
}
for(i=1;i<=y;i++)
{if(y>=50)
{
printf("l");
y=y-50;}
}
for(i=1;i<=y;i++)
{if(y>=10)
{
printf("x");
y=y-10;}
}
for(i=1;i<=y;i++)
{if(y>=5)
{
printf("v");
y=y-5;}
}
for(i=1;i<=y;i++)
{if(y>=1)
{
printf("i");}
}
printf("\n");
}
#include
void roman(void);
main()
{
roman();
getch();
}
void roman()
{
int y,i;
printf("input the year to get its roman numeral:\n");
scanf("%d",&y);
for(i=1;i<=y;i++)
{if(y>=1000)
{
printf("m");
y=y-1000;}
}
for(i=1;i<=y;i++)
{if(y>=500)
{
printf("d");
y=y-500; }
}
for(i=1;i<=y;i++)
{if(y>=100)
{
printf("c");
y=y-100;}
}
for(i=1;i<=y;i++)
{if(y>=50)
{
printf("l");
y=y-50;}
}
for(i=1;i<=y;i++)
{if(y>=10)
{
printf("x");
y=y-10;}
}
for(i=1;i<=y;i++)
{if(y>=5)
{
printf("v");
y=y-5;}
}
for(i=1;i<=y;i++)
{if(y>=1)
{
printf("i");}
}
printf("\n");
}