Aim: Write A Program To Calculate Power of A Number: Practical No. 1
Aim: Write A Program To Calculate Power of A Number: Practical No. 1
Aim: Write A Program To Calculate Power of A Number: Practical No. 1
Algorithum :
Exponent !=0
i. Value *=base
ii. –exponent
as int
No
if(n&n-1==0
and n!=0)
Yes
Count=log(n)/log(2) ;
Print(count)
End
Program :
#include<stdio.h>
int main(){
long value = 1;
scanf("%d", &base);
scanf("%d", &exponent);
value *= base;
--exponent;
return 0;
Output :
Practical No.2
Algorithum :
Step 1: Start
5.2 num=num/10
Step 6: IF sum==temp
ELSE
Step 7: Stop
Flowchart : Start
Assign sum=0
Whether temp=0
Reached ?
Temp = temp/10
if num ==sum
Stop
Program :
#include <math.h>
#include <stdio.h>
int main() {
scanf("%d", &num);
originalNum = num;
originalNum /= 10; }
if ((int)result == num)
else
return 0;
}
Output :
Practical No. 3
Aim : Write a Program to convert binary into decimal and vice versa.
Algorithum :
Step 1: Start
Step 2: Read the binary number from the user, say ‘n’
n = n/10
d = d + (remainder * 2<sup>i</sup>)
Increment i by 1
Step 7: Stop
Flowchart : Start
d = d + (remainder *2 ^i)
n = n/10
Remainder = n % 10
No
Is n=0 ?
Yes
Display d
Stop
Program :
#include <math.h>
#include <stdio.h>
int main() {
long long n;
scanf("%lld", &n);
return 0;
while (n != 0) {
rem = n % 10;
n /= 10;
++i;
return dec;
}
Output :
Practical No. 4
Algorithum:
Step 1 : Begin
Step 9 : EXIT.
Flow chart : Yes
Start Case1 Add()
No
Read a
Yes Substract ()
Case2
Read b
No
No
Read Choices
Yes Divide ()
Case4
Switch (choice) No
Yes
Case5 Mod()
No
Yes
End Default
Program :
#include <stdio.h>
int main() {
char op;
scanf("%c", &op);
switch (op) {
case '+':
break;
case '-':
break;
case '*':
break;
case '/':
break;
default:
return 0;
}
Output :