Q. If sum of two integer is 14 and if one of them is 8 then find other integer. Ans: Well, this is very simple. Simply, one integer is 8 and sum of two integers is 14. So, we need to subtract the number 8 from their sum of 14 to get the second number. So, the second number is: 14 - 8 = 6 C-Program of this task Code---> #include<stdio.h> int main () { int num1 = 8 , num2 , sum = 14 ; num2 = sum - num1 ; printf ( "The second number is: %d" , num2 ); return 0 ; }
In this C-program we will calculate the power of a number and print the result. The number will be taken from the user.
We can calculate the power of a number in two ways. In the first way, we will use a loop (while loop) and calculate it.
In the second way, we will calculate it with the help of a function , called "pow()".
First way: Calculate with loop
input:
The number(i.e : base) and the power(i.e : exponent)(i.e : 5,6,9 etc.)output:
The result of it's calculation.
CODE---->
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,r=1,n;
clrscr();
printf("Please, Enter a number (base):");
scanf("%d",&n);
printf("\nPlease, Enter it\'s power (exponent):");
scanf("%d",&a);
b=a;
while(a!=0)
{
r=r*n;
a--;
}
printf("\nThe result of %d^%d = %d ",n,b,r);
getch();
}
RESULT:
*Note : The above program will work only if the number and the exponent are positive integers.
Second way: Calculate with function pow()
input:
The number(i.e : base) and the power(i.e : exponent)(i.e : 5,6,9 etc.)output:
The result of it's calculation.
CODE---->
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float a,r,n;
clrscr();
printf("Please, Enter a number (base):");
scanf("%f",&n);
printf("\nPlease, Enter it\'s power (exponent):");
scanf("%f",&a);
r=pow(n,a);
printf("\nThe result of %f^%f = %f ",n,a,r);
getch();
}
Thank You So Much for your support. We do this for you and we are very much delighted by such appreciation.
ReplyDeleteThank You Sathya.