Function Main
Declare Integer A
Declare Integer B
Declare Integer C
Declare Integer Delta
Declare Real X1
Declare Real X2
Output "Enter coefficient of X^2:"
Input A
Output "Enter coefficient of X:"
Input B
Output "Enter known term:"
Input C
If A = 0
Output "Equarion:"
Assign X1 = -C / B
Output "The solution is X = " & X1
Else
Assign Delta = B^2 - 4*A*C
If Delta < 0
Output "There are no real solutions"
Else
If Delta = 0
Assign X1 = -B / (2*A)
Output "Two real and coincident solutions"
Output "X1 = " & X1
Output "X2 = " & X1
Else
Assign X1 = -B - SQRT(Delta) / (2*A)
Assign X2 = -B + SQRT(Delta) / (2*A)
Output "Two real and distinct solutions"
Output "X1 = " & X1
Output "X2 = " & X2
End
End
End
End
Function Main
Declare Integer y
Declare Integer w
Declare Integer d
Declare Integer a
Output "Enter total number of days:"
Input d
Assign y = d / 365
Assign a = d MOD 365
Assign w = a / 7
Assign d = a MOD 7
Output "Years:" & ToString(y) & ToChar(10) & ToChar(13) & "Weeks: " & ToString(w) & ToChar(10) & ToChar(13) & "Days: " & ToString(d)
End
#include <stdio.h>
int main() {
int y;
int w;
int d;
int a;
printf("Enter total number of days:\n");
scanf("%d", &d);
y = (int) ((double) d / 365);
a = d % 365;
w = (int) ((double) a / 7);
d = a % 7;
printf("Years: %d\nWeeks: %d\nDays: %d\n", y, w, d);
return 0;
}
Function Main
Declare Integer n
Declare Integer k
Declare Integer r
Output "Insert a number: "
Input n
Assign k = 1
Output "All divisor of the number: "
While k <= n
Assign r = n mod k
If r = 0
Output k
End
Assign k = k + 1
End
End
#include <stdio.h>
int main() {
int n;
int k;
int r;
printf("Insert a number: \n");
scanf("%d", &n);
k = 1;
printf("All divisor of the number: \n");
while (k <= n) {
r = n % k;
if (r == 0) {
printf("%d\n", k);
}
k = k + 1;
}
return 0;
}
Function Main
Declare Integer num
Output "Enter the Binary number: "
Input num
Output "The decimal number is:"
Output BinaryToDecimal(num)
End
Function BinaryToDecimal (Integer num)
Declare Integer rem
Declare Integer sum
Declare Integer power
Assign sum = 0
Assign power = 0
While num > 0
Assign rem = num MOD 10
Assign num = num / 10
Assign sum = sum + rem * POW(2, power)
Assign power = power + 1
End
Return Integer sum
Function POW (Integer Base, Integer Exponent)
Declare Integer Result
If Exponent = 0
Assign Result = 1
Else
Assign Result = Base * POW(Base, Exponent -1)
End
Return Integer Result
#include <stdio.h>
int BinaryToDecimal(int num);
int POW(int Base, int Exponent);
int main() {
int num;
printf("Enter the Binary number: \n");
scanf("%d", &num);
printf("The Decimal number is:\n");
printf("%d\n", BinaryToDecimal(num));
return 0;
}
int BinaryToDecimal(int num) {
int rem;
int sum;
int power;
sum = 0;
power = 0;
while (num > 0) {
rem = num % 10;
num = (int) ((double) num / 10);
sum = sum + rem * POW(2, power);
power = power + 1;
}
return sum;
}
int POW(int Base, int Exponent) {
int Result;
if (Exponent == 0) {
Result = 1;
} else {
Result = Base * POW(Base, Exponent - 1);
}
return Result;
}
Function Main
Declare Integer i, j, r
Output "Input number of rows : "
Input r
For i = 0 to r
For j = 1 to r-i
Output " "
End
For j = 1 to 2*i-1
Output "*"
End
Output ""
End
For i = r-1 to 1 decreasing
For j = 1 to r-i
Output " "
End
For j = 1 to 2*i-1
Output "*"
End
Output ""
End
End
Function Main
Declare Integer i, j, space, rows, k
Output "Input number of rows : "
Input rows
Assign space = rows+4-1
For i = 1 to rows
For k = space to 1 decreasing
Output " "
End
For j = 1 to i
Output "* "
End
Output ""
Assign space = space -1
End
End
Function Main
float var = 23.564327;
Declaring pointer variables upto level_4
Initializing pointer variables
ptr1 = &var;
ptr2 = &ptr1;
ptr3 = &ptr2;
ptr4 = &ptr3;
Output values
"Value of var = %f\n", var);
"Value of var using level-1"
" pointer = %f\n",
*ptr1);
"Value of var using level-2"
" pointer = %f\n",
**ptr2);
"Value of var using level-3"
" pointer = %f\n",
***ptr3);
"Value of var using level-4"
" pointer = %f\n",
****ptr4);
End
Value of var = 23.564327
Value of var using level-1 pointer = 23.564327
Value of var using level-2 pointer = 23.564327
Value of var using level-3 pointer = 23.564327
Value of var using level-4 pointer = 23.564327
Function Main
Declare Integer A
Declare Integer B
Declare Integer res
Output "Insert 2 numbers to calculate GCD"
Output "First number: "
Input A
Output "Second number"
Input B
Assign res = GCD(a,b)
Output res
End
Function GCD (Integer a, Integer b)
Declare Integer res
If a = 0
Assign res = b
Else
Assign res = GCD(b MOD a, a)
End
Return Integer res
#include <stdio.h>
int GCD(int a, int b);
int main() {
int a;
int b;
int res;
printf("Insert 2 numbers to calculate GCD:\n");
printf("First number: \n");
scanf("%d", &a);
printf("Second number:\n");
scanf("%d", &b);
res = GCD(a, b);
printf("%d\n", res);
return 0;
}
int GCD(int a, int b) {
int res;
if (a == 0) {
res = b;
} else {
res = GCD(b % a, a);
}
return res;
}
Function Main
Declare Integer fact1
Declare Integer fact2
Output " First factor"
Input fact1
Output "Second factor"
Input fact2
Output multiply(fact1, fact2)
End
Function multiply (Integer x, Integer y)
Declare Integer result
If y = 0
Assign result = 0
End
If y > 0
Assign result = x + multiply(x, y-1)
End
If y < 0
Assign result = -multiply(x, -y)
End
Return Integer result
#include <stdio.h>
int multiply(int x, int y);
int main() {
int fact1;
int fact2;
printf("First factor:\n");
scanf("%d", &fact1);
printf("Second factor:\n");
scanf("%d", &fact2);
printf("%d\n", multiply(fact1, fact2));
return 0;
}
int multiply(int x, int y) {
int result;
if (y == 0) {
result = 0;
}
if (y > 0) {
result = x + multiply(x, y - 1);
}
if (y < 0) {
result = (int) (-multiply(x, (int) (-y)));
}
return result;
}
Function Main
Declare Integer n1, n2
Output "This is a call by value add(2, 30):"
Output add(2, 3)
Output "Input first number (n1):"
Input n1
Output "Input second number(n2):"
Input n2
Output "This is a call by reference add(n1, n2):"
Output add(n1, n2)
End
Function add (Integer first, Integer second)
Declare Integer result
Assign result = first + second
Return Integer result
#include <stdio.h>
int add(int first, int second);
int main() {
int n1, n2;
printf("This is a call by value add(2, 3):\n");
printf("%d\n", add(2, 3));
printf("Input first number(n1):\n");
scanf("%d", &n1);
printf("Input second number(n2):\n");
scanf("%d", &n2);
printf("This is a call by reference add(n1, n2):\n");
printf("%d\n", add(n1, n2));
return 0;
}
int add(int first, int second) {
int result;
result = first + second;
return result;
}