Search This Blog

Caesar Cipher Algorithm Program in C

Today we will learn the Caesar Cipher Algorithm Program in C with output & explanation. Ceaser Cipher is also named as shift cipher, Caesar shift or Caesar's code.

For example, if entered key is 2 then characters will be replaced by 2 characters down to it. Like, A will be replaced by C, B by D and so on. Below image show shifting of characters by key value 2.
Ceasar Cipher Algorithm Character Shifting - Encryption - C Program

Encryption & Decryption of a letter x by a shift n can be described mathematically as below.
Caesar Cipher Algorithm Encryption and Decryption modular arithmetic equation

/*Caesar Cipher Program in C*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(void){

int key;
char plainText[101];
        int i=0;
int cypherValue;
char cypher;
clrscr();

printf("Please enter the plain text you want to encrypt: ");

fgets(plainText, sizeof(plainText), stdin);

        printf("\nPlease enter key: ");
        scanf("%d",&key);

        printf("\nThe ciphered text is : ");
while( plainText[i] != '\0' && strlen(plainText)-1 > i){
cypherValue = ((int)plainText[i] -97 + key) % 26 + 97;
cypher = (char)(cypherValue);

printf("%c", cypher);
i++;
}
printf("\n\n");

system("pause");
}
Output:
Please enter the plain text you want to encrypt: HelloWorld
The ciphered text is: JgnnqYqtnf




Read more »

Insertion Sort Algorithm Program in Kotlin

In this article, we will write an insertion sort algorithm program in Kotlin. Below is the complexity comparison of insertion sort.

Best-case performance: O(n) comparisons, O(1) swaps
Average performance: О(n2) comparisons, swaps
Worst-case space complexity: О(n) total, O(1) auxiliary

Source Code:
fun main(arg: Array<String>)
{
    try
    {
        print("Enter size of array : ")
        var n = readLine()!!.toInt()

        println("Enter elements : ")
        var A = Array(n, { 0 })
        for (i in 0 until n) {
            A[i] = readLine()!!.toInt()
        }

        insertion_sort(A,A.size)

        println("Sorted array is : ")
        for (i in 0 until n){
            print("${A[i]}  ")
        }
    }
    catch(e: Exception)
    {
        print("$e")
    }
}

/* Function to sort an array using insertion sort*/
fun insertion_sort(A: Array<Int>, n : Int)
{
    var n = A.size
    var i: Int
    for (j in 1 until n)
    {
        var key = A[j]
        i = j - 1
        while (i >= 0 && A[i] > key) {
            A[i + 1] = A[i]
            i--
        }
        A[i + 1] = key
    }
}
Output:
Enter size of array : 5
Enter elements :
12
10
14
18
16
Sorted array is :
10  12  14  16  18
Insertion Sort Algorithm Program in Kotlin - Output
Insertion Sort Algorithm Program in Kotlin - Output

Description:
In this program, we will take the size of an array from the end user. Next, it will ask to enter the number of elements of array. It will be stored in array A[i] = readLine()!!.toInt() using for loop. At this point elements of an array are not in sorted sequence.

Next, we have called the function fun insertion_sort(A: Array<Int>, n : Int), which accepts an array to be sorted and size of an array. A sorted array will be printed using print() function. More in this, we have used try{} catch{} blocks to validate user input.
Read more »

Program to calculate compound interest in Kotlin

In this article, We will learn program to calculate compound interest in Kotlin. In simple terms, Compound interest is the sum of principal amount and interest of interest.

Compound Interest Formula Kotlin
Compound Interest Formula

Source Code:
fun main(args: Array<String>)
{
    try
    {
        print("Enter principle amount : ")
        val principle = readLine()!!
        print("Enter interest rate : ")
        val rate = readLine()!!
        print("Enter number of years : ")
        val time = readLine()!!

        val ci = principle.toDouble() * Math.pow((1 + rate.toDouble()/100.00),time.toDouble())
        println("Compound Interest is : $ci")
    }
    catch (exception : NumberFormatException)
    {
        print(exception)
    }
}
Output:
Enter principle amount : 2000
Enter interest rate : 2
Enter number of years : 3
Compound Interest is : 2122.416
Calculate Compound Interest in Kotlin - Output
Description:
In this program, we will take input from the user to enter to get principal amount, rate and years value. To do so we have used readLine() function.

compound interest formula is A = P(1 + r/n)^nt. Where "P" is the principal amount, "r" is an annual nominal interest rate and "n" is the number of years. Same is printed using print() function.
Read more »

Program to find area of Triangle in Kotlin

Area of Triangle in Kotlin - This Kotlin program will read height and base of the Triangle to Calculate Area of the Triangle.

Source Code:
fun main(args: Array<String>)
{
        print("Enter Base Width : ")
        val base = readLine()!!
        print("Enter Height : ")
        val height = readLine()!!

        val area: Double
        if(base.toIntOrNull() != null && height.toIntOrNull() != null)
        {
            area = (base.toDouble() * height.toDouble()) / 2
            print("Area of Rectangle is : $area")
        }
        else
        {
            print("Please enter valid input.")
        }
}
Output:
Enter Base Width: 10
Enter Height: 10
Area of Rectangle is: 50.0
Kotlin program to find Area of Triangle - Output
Kotlin program to find Area of Triangle - Output

Description:
In this program, we will take input from the user to enter to get base and height value of the triangle. To do so we have used readLine() function.

Next, we have checked that input accepted from the user is valid integer or decimal number. If an input is not valid then it will print the message to enter valid input.

To find the area of a triangle we have used an equation (base * height ) / 2, which is equivalent to (b*h)/ 2. Finally, an area of the triangle is printed using print() function.
Read more »

Program to find area of rectangle in Kotlin

In this article, we will learn simple Kotlin program to find the area of a rectangle.

Source Code:
fun main(args: Array<String>)
{
    print("Enter the length of Rectangle : ")
    val length = readLine()!!
    print("Enter the width of Rectangle : ")
    val width = readLine()!!

    val area: Double
    if(length.toIntOrNull() != null && width.toIntOrNull() != null)
    {
        area = length.toDouble()  * width.toDouble();
        print("Area of Rectangle is : $area")
    }
    else
    {
        print("Please enter valid input.")
    }
}
Output:
Enter the length of Rectangle: 2
Enter the width of Rectangle: 4
Area of Rectangle is: 8.0
Program to find an area of the rectangle in Kotlin
Program to find an area of the rectangle in Kotlin - Output

Description:
In this program, we will take input from the user to enter to provide the length and width value of the rectangle. To do so we have used readLine() function.

Next, we have checked that input accepted from the user is valid integer or decimal number. If an input is not valid then it will print the message to enter valid input.

To find the area of a rectangle we have used an equation length * width, which is equivalent to A = w * l. Finally, an area of the rectangle is printed using print() function.

Read more »

Program to find perimeter of a circle in Kotlin

In this article, we will learn simple Kotlin program to find the perimeter of a circle.

Source Code:
fun main(args: Array<String>)
{
    print("Enter circle radius : ")
    val input = readLine()!!
    val radius: Double
    if(input.toIntOrNull() != null)
    {
        radius = input.toDouble()
        val pi: Double=3.14159
        val perimeter: Double = 2 * pi * radius
        print("Perimeter of Circle is : $perimeter")
    }
    else
    {
        print("Please enter valid input.")
    }
}
Output:
Enter circle radius : 10
Perimeter of Circle is : 62.8318
Program to find the perimeter of a circle in Kotlin
Program to find the perimeter of a circle in Kotlin - Output

Description:
In the above program, we will take input from a user to know the radius of a circle. To do so we have used readLine() function. Next, we have checked that input accepted from the user is valid integer or decimal number. If an input is not valid then it will print the message to enter valid input.

If the input is a valid integer or decimal number, we will store it to a variable named val perimeter. Next, we have taken variable pi to hold the value of mathematical constant π, which is 3.14159. To find the perimeter of a circle we have used an equation 2 * pi * radius, which is equivalent to 2πr.

Read more »

Program to find area of circle in Kotlin

In this article, we will learn simple Kotlin program to find an area of a circle.

Source Code:
fun main(args: Array<String>)
{
    print("Enter circle radius : ")
    val input = readLine()!!
    val radius: Double
    if(input.toIntOrNull() != null)
    {
        radius = input.toDouble()
        val pi: Double=3.14159
        val area: Double = pi * radius * radius
        print("Area of Circle is : $area")
    }
    else
    {
        print("Please enter valid input.")
    }
}
Output:
Enter circle radius : 10
Area of Circle is : 314.159
Program to find an area of a circle in Kotlin
Program to find an area of a circle in Kotlin - Output

Description:
In the above program, we will take input from a user to know the radius of a circle. To do so we have used readLine() function. Next, we have checked that input accepted from the user is valid integer or decimal number. If an input is not valid then it will print the message to enter valid input.

If the input is a valid integer or decimal number, we will store it to a variable named val radius. Next, we have taken variable pi to hold the value of mathematical constant π, which is 3.14159. To find the area of a circle we have used an equation pi * radius * radius, which is equivalent to πr2.









Read more »

Hello World program in Kotlin

In this article, you will learn how to print Hello World in Kotlin programming. Hello World is the simplest program in any programming language.

Source Code:
fun main(args: Array<String>)
{
    print("Hello World")
}
Output:
Hello World
Description:
Here, we are starting with the simplest program to introduce you to Kotlin programming language. Unlike the Java programming, Class declaration is not mandatory in Kotlin programming language. Kotlin compiler creates class internally.

In Kotlin programming, the main function is mandatory. The Kotlin program starts executing the program from the main function. Signature of the main method is fun main(args: Array<String>) {}.

print() function prints the message entered in double quotes. Where println() function prints the message in the new line.

Read more »

Program to reverse a string in kotlin

In this article, you will learn to reverse a string in different ways. We will learn step by step, how to reverse a string in Kotlin.


1. Reverse a string in Kotlin using for loop
Source Code:
fun main(args: Array<String>)
{
    val str = "Hello World"
    var charOfString  = ""
    for (i in 0..str.length - 1)
    {
        charOfString += str[str.length - 1 -i].toString()
    }
    print("Reversed String: $charOfString")
}
Output:
Reversed String: dlroW olleH
Reverse a string in kotlin using for loop - output
Reverse a string in kotlin using for loop - output
Description:
In the above program, we have used for loop to reverse a string. First, we have stored the string in str variable which we want to reverse.

In a next line, for loop will iterate until str.length - 1. With each iteration, it will find the value of a string using str[str.length - 1 -i]. Same will be printed using print() function.


2. Reverse a string in Kotlin using recursion
Source Code:
fun main(args: Array<String>) {
    val sentence = "Hello World"
    val reversed = reverse(sentence)
    println("The reversed sentence is: $reversed")
}

fun reverse(sentence: String): String
{
    if (sentence.isEmpty())
    {
        return sentence
    }
    return reverse(sentence.substring(1)) + sentence[0]
}
Output:
The reversed sentence is: dlroW olleH
Reverse a string in kotlin using recursion - output
Reverse a string in kotlin using recursion - output
Description:
In the above program, we have used recursion to reverse the sentence string. Here we have written new function reverse(sentence: String): String, which takes a string input and returns string output.

Next, we have called reverse function and passed a string which wanted to reverse. As you can see inside the reverse() function we have called the function reverse(sentence.substring(1)) itself. It will recursively call itself until a string is empty sentence.isEmpty().

Read more »

Program to add two numbers in kotlin

In this article, we will share an example of Kotlin program to add two numbers. Further, you will learn to store the value in a variable and then sum two variables. Let's see how to write a program to add two integer number in Kotlin.

Source Code:
fun main(args: Array<String>) {

    print("Enter first number : ")
    val firstnumber = readLine()!!
    print("Enter second number : ")
    val secondnumber = readLine()!!

    if(firstnumber.toIntOrNull() != null && secondnumber.toIntOrNull() != null)
    {
        val sum: Int = firstnumber.toInt() + secondnumber.toInt()
        println("The sum two number is : $sum")
    }
    else
    {
        println("Please enter valid first and second number.")
    }
}

Output:
Enter first number : 12
Enter second number : 13
The sum two number is : 25
Kotlin program to add two numbers - output
Kotlin program to add two numbers - output

Description:
In this program, we have taken two variable "firstnumber" and "secondnumber", in which we are taking input from the end user. To do so we are using readLine()!! function.

After taking two number from the user, we have checked that entered text is number or not. To do so, we have used toIntOrNull() function. if the text is not integer number, it will return null value.

If it does satisfy the condition and entered text are integer number, then it will add two number using "+" operator. Next, it will print the same using print() function.

If it does not satisfy the condition, it will go to else statement and print the message to enter valid numbers.
Read more »

Program to check number is prime or not in kotlin

In this article, we will write a program to check whether the entered number is prime or not in Kotlin Programming.

1. Kotlin Program to check prime number using for loop
import java.lang.Integer.parseInt

fun main(args: Array<String>)
{
       print("Please enter numer : ")
       val intInput = readLine()!!
       var isNumber = true

       try
       {
           val number = parseInt(intInput)
       }
       catch (e: NumberFormatException)
       {
           isNumber = false
       }

       if(isNumber)
       {
            val num = intInput.toInt()
            var flag = false
            for (i in 2..num / 2)
            {
                // condition to check prime number
                if (num % i == 0) {
                    flag = true
                    break
                }
           }

            if (!flag)
                println("$num is a prime number.")
            else
                println("$num is not a prime number.")
        }
        else
        {
            println("$intInput is not a number, Please enter valid input.")
        }
}
Output:
Please enter numer : 21
21 is not a prime number.
Kotlin program to check number is prime or not using for loop - output
Kotlin program to check number is prime or not using for loop - output

Description:
1. In this program, we have taken input from the user using readLine() method.
2. Next validate enter input using parseInt() method, whether enter input is number or not.
2.1. If an entered input is not number, it will just print that "Entered text is not a number, please enter valid input.".
3. Next, inside the for loop, it will check whether the number is divisible by any number in the given range (2..num/2).
4. It is divisible, a flag will set to true and it will break out the loop.
5. if a flag is set to false then the number is prime, else it's not.


2. Kotlin Program to check prime number using a while loop
import java.lang.Integer.parseInt

fun main(args: Array<String>) {
    print("Please enter numer : ")
    val intInput = readLine()!!
    var isNumber = true

    try
    {
        val number = parseInt(intInput)
    }
    catch (e: NumberFormatException)
    {
        isNumber = false
    }

    if(isNumber)
    {
val num = intInput.toInt()
var i = 2
var flag = false
while (i <= num / 2) {
// condition for nonprime number
if (num % i == 0) {
flag = true
break
}
++i
}

if (!flag)
{
println("$num is a prime number.")
}
else
{
println("$num is not a prime number.")
}
    }
    else
    {
        println("$intInput is not a number, Please enter valid input.")
    }
}
Output:
Please enter numer : 23
23 is a prime number.
Kotlin program to check number is prime or not using for loop - output
Kotlin program to check number is prime or not using while loop - output

Description:
1. In this program, we have taken input from the user using readLine() method.
2. Next validate enter input using parseInt() method, whether enter input is number or not.
2.1. If an entered input is not number, it will just print that "Entered text is not a number, please enter valid input.".
3. Next, While loop will run until i <= num/2.With each iteration, it will check if num is divisible by i or not. if it is, then it will break and set the flag to true.
4. if a flag is set to false then the number is prime, else it's not.

Read more »

Program to find file extension in kotlin

In this article, we will share the program to find file extension with an output.

Program:
fun main(args: Array<String>) {
    val fileFullPath = "AskforProgram/Kotlin/Examples/getFileNameExample.kt"
    val fileExtension = fileFullPath.substringAfterLast(".")

    println("File Extention: $fileExtension")
}

Output:
Kotlin program to find file extension with output
Kotlin program to find file extension with an output

Program Description:
1 fileFullPath variable contains a sample path of the directory.

2 .substringAfterLast() - function will find the last index of "." character, and then it will return the string from that index to end of a string.

3 println() function will print file extention.

Read more »

What is kotlin file extension

You might be curious to know different file extensions in Kotlin Programming. Below are the 3 file extension I have come to know.

.kt file extension: a source file in Kotlin
.ktm file extension: a module file in Kotlin
.kts file extension: a shell script in Kotlin

Related Programs:
1. Program to find directory/application path in Kotlin
2. Kotlin program to find the file extension
Read more »

Kotlin program to find directory/application path

In this article, we will share program to find directory/application path with an output.

Program: Program to find directory path in Kotlin
fun main(args: Array<String>) {

val fileFullPath = "AskforProgram/Kotlin/Examples/getFileNameExample.kt"
val fileDirectory = fileFullPath.substringBeforeLast("/")

println("dir: $fileDirectory")
}

Output:

Kotlin program to find application directory path using substringBeforeLast() - Output
Kotlin program to find application directory path using substringBeforeLast() - Output


Program Description:
1 fileFullPath variable contains a sample path of the directory.

2 .substringBeforeLast() - function will find last index of "/" character, and then it will return string till that index from first.

3 println() function prints directory path.

Read more »

Kotlin Setup: Install IntelliJ IDEA for Windows

How to Download IntelliJ IDEA in windows for Kotlin

In this article, we will learn to install the intelligent IDEA for windows to learn the Kotlin programming.

let's get started, simply search "IntelliJ IDEA for Windows" in Google and hit enter, here you will get the first link from the jetbrains.com.

How to download IntelliJ IDEA in Windows for Kotlin
How to download IntelliJ IDEA in Windows for Kotlin


Click on it and you will navigate it to space where you will find the two version the ultimate version and community version.

Simply select the Community Edition that is a free and open source. Ultimate edition is the paid version where you can go for the enterprise development.

Down the side, in the same link, you will find the key difference between the commercial license and open source license.

Install IntelliJ IDEA in windows for Kotlin

Once you have downloaded IDEA, click on downloaded .exe file like "ideaIC-2018.1.5" to install.
IntelliJ IDEA Community Edition Setup Kotlin
1. IntelliJ IDEA Community Edition Setup Kotlin
In this step, you will be asked to close all unnecessary applications. So that IntelliJ IDEA can update all the relevant system files without having reboot your computer.
IntelliJ IDEA Community Edition Setup-Choose Location-Kotlin
2. IntelliJ IDEA Community Edition Setup-Choose Location-Kotlin

In the second step, you will be asked to choose the folder in which you want to install IntelliJ IDEA Community Edition for Kotlin.
IntelliJ IDEA Community Edition Setup-Import Settings- Kotlin
3. IntelliJ IDEA Community Edition Setup-Import Settings- Kotlin
In the third step, You will be asked to import settings of the previous version or select option to not to import settings.
IntelliJ IDEA Community Edition Setup-JetBrains Privacy Policy-Kotlin
4.IntelliJ IDEA Community Edition Setup-JetBrains Privacy Policy-Kotlin
In this step, simply read all the privacy policy and Accept it.

IntelliJ IDEA Community Edition data Sharing-Setup-D Kotlin
5. IntelliJ IDEA Community Edition data Sharing-Setup-D Kotlin
If you want to help JetBrains to improve its product by sending data with them, then press "Send Usage Statistics" else press "Don't Send".

IntelliJ IDEA Community Edition Setup-Set UI Theme- Kotlin
6. IntelliJ IDEA Community Edition Setup-Set UI Theme- Kotlin
In this step, You will have to set the UI theme of your choice.

IntelliJ IDEA Community Edition Setup-Customize Default Plugin- Kotlin
7. IntelliJ IDEA Community Edition Setup-Customize Default Plugin- Kotlin
Simply click on a button "Next: Featured Plugins" and keep all default plugins.

IntelliJ IDEA Community Edition Setup-Customize Featured Plugin- Kotlin
8. IntelliJ IDEA Community Edition Setup-Customize Featured Plugin- Kotlin
In the next step, You can download some of the featured plugins of your choice. Next click on button "Start using IntelliJ IDEA".
IntelliJ IDEA Community Edition Setup-Community 2018- Kotlin
9. IntelliJ IDEA Community Edition Setup-Community 2018- Kotlin

IntelliJ IDEA Community Edition Setup-Create Project- Kotlin
10. IntelliJ IDEA Community Edition Setup-Create Project- Kotlin
It's Done, IntelliJ IDEA successfully installed. You are all set to create your first project for Kotlin.











Read more »

Kotlin Setup: Install Java JDK for Windows

In this article, we are going to install the Java JDK for Kotlin. You might be wondering, why we require the Java JDK. Kotlin requires Java Virtual Machine to execute programs. Java JDK(Java development kit) contains the compiler, interpreter and Java Runtime environment. With the help of it, we are going to execute our Kotlin programs. 

How to Install JAVA JDK for Coding in Kotlin, Setup Kotlin on Windows
How to Install JAVA JDK for Coding in Kotlin, Setup Kotlin on Windows

Install Java JDK in our Windows PC

Simply go to Google and search for "Java JDK for Windows 8". In the Google search, first result link you will get is of oracle.com. Navigated to the official page of oracle.com where you can simply download the Java for windows. Here you can see "Java SE Downloads", SE stands for the standard edition.

Simply click and install the Java standard edition. On the redirected page, you will find the Java SC development kit with the version. Accept the license option, down the side you will find the link for Java windows 32-bit & Java windows 64-bit machine.

Java SE Development Kit for Kotllin
Java SE Development Kit for Kotllin
After you download the Java JDK you will find it inside the default download folder or wherever you have downloaded it. Simply double-click on it and launch the application and install it. So here it is the Java JDK has been successfully installed.

Verify whether the Java has been installed in your PC or not?

Simply search command prompt CMD, right click on it and then run as administrator. Navigate to "C:\Windows", type java and press enter. It will bring the list of Java commands that you can use.

So if you get this then your Java has been installed successfully in your PC, otherwise please follow the steps again.
Read more »

G02 CNC Code Circular Interpolation Clockwise - CNC Programming Example

You might be interested in learning CNC programming basics. Let's start with g02 circular interpolation example. CNC programming codes are easy to understand even for beginner level CNC Machinist and CNC Programmers.

Below is the CNC programming examples with Drawing. 

CNC Programming Example G02 CNC Code Circular Interpolation Clockwise
CNC Programming Example G02 CNC Code Circular Interpolation Clockwise

N10 T0101
N20 G92 S1000 M42
N30 G96 S200 M03
N40 G00 X0 Z5
N50 G01 Z0 F0.5
N60 G01 X80 F0.2
N70 G02 X100 Z-30 I50 K0
N80 G01 Z-120
N90 G00 X200 Z200
M30

CNC Code Explanation

G92 CNC Code: Which was mostly used for older machines. G92 CNC code is utilized to demonstrate the machine where the zero-point of the program is.
G96 CNC Code: Constant surface speed.
G02 CNC Code: Circular Interpolation Clockwise, CW.

G2/G02 Code explanation

Action: Circular Moves
ANSI Standard: Yes
Requirements: Point to move to, Feed Rate at which to move
Options: I, J, K and R
G02 X... Z... R...
G02 X... Z... I... K...

How to use G02 code/command

You must know the present location of the machine instrument as for the part, the point where the circular segment will end and feed rate at which you need to cut the curve.

Additionally, you need to know the location of the circular segment with respect to start point of the arc. The begin purpose of the circular segment(arc) is that point to which you move the machine where the bend is to start.

Imagine vertical line and you are moving along the line from base to top. As you get to the finish of the line you can swing to left or you can swing to the right. Regardless of whether the arc turns to one left or right is determined by the center of the arc.

For example, you are moving to the right on horizontal line and at the end, you want to draw an arc.
Then the center of an arc would be on the Y axis, either +Y or -Y.

The Commands which tell the machine about the center of an arc are I, J and K command.
X: Endpoint of arc in the x-axis.
Z: Endpoint of arc in the z-axis.
I: Distance from arc start point to arc center point in the x-axis.
K: Distance from arc start point to arc center point in the z-axis.

Similar Search:
how to program a radius on a CNC lathe, circular interpolation milling program, Fanuc circular interpolation examples, CNC codes, CNC programming, g02 examples, go2 CNC code, CNC lathe programming, cnc g code, cnc go2, g code cnc, g code g02, g code examples, go2 code, g02 g code example, g02 lathe, g02 programming example
Read more »

C Graphics Program for A Man Walking In Rain

Program in c to draw a Man walking in the rain using graphics (CG) program. Program is made using 3 different objects. A man with Umbrella, Rain and Ground.

First we have created function DrawManWithUmbrella which will Man and Umbrella using pieslice, line & circle functions. We have used pieslice & line functions to draw umbrella, circle & line functions to draw head, line function to draw hands & legs.

To draw rain we have used Rand() and Line() functions. Rand() function generates sequence of random numbers, which are location coordinates on-screen to draw rain using line() function. Speed of man can be adjusted using delay() function. Higher the delay lesser the speed.

Program in c to draw a Man walking in the rain using graphics program


#include<stdio.h>
#include<graphics.h>

#define ScreenWidth getmaxx()
#define ScreenHeight getmaxy()
#define GroundY ScreenHeight*0.75

int ldaisp=0;
void DrawManWithUmbrella(int a,int ldaisp)
{
    //Draw Umbrella
    pieslice(a+20,GroundY-120,0,180,40);
line(a+20,GroundY-120,a+20,GroundY-70);

    //Draw head
circle(a,GroundY-90,10);
line(a,GroundY-80,a,GroundY-30);

    //Draw hand
line(a,GroundY-70,a+10,GroundY-60);
line(a,GroundY-65,a+10,GroundY-55);
line(a+10,GroundY-60,a+20,GroundY-70);
line(a+10,GroundY-55,a+20,GroundY-70);

    //Draw legs
line(a,GroundY-30,a+ldaisp,GroundY);
line(a,GroundY-30,a-ldaisp,GroundY);
}

void Rain(int a)
{
int i,rx,ry;
for(i=0;i<400;i++)
{
rx=rand() % ScreenWidth;
ry=rand() % ScreenHeight;
if(ry<GroundY-4)
{
if(ry<GroundY-120 || (ry>GroundY-120 && (rx<a-20 || rx>a+60)))
line(rx,ry,rx+0.5,ry+4);
}
}
}

void main()
{
int gd=DETECT,gm,a=0;
initgraph(&gd,&gm,"C:\TurboC++\Disk\TurboC3\BGI");

    while(!kbhit())
{
//Draw Ground
line(0,GroundY,ScreenWidth,GroundY);
Rain(a);
ldaisp=(ldaisp+2)%20;
DrawManWithUmbrella(a,ldaisp);
delay(40);
cleardevice();
a=(a+2)%ScreenWidth;
}
getch();
}


Program in c to draw a Man walking in the rain using graphics programming.
Read more »

Understand AWS Regions, Availability Zones and Edge Locations

In this article i have tried to explain difference between AWS Region vs AWS Availability zone vs AWS Edge Location. These are the basic terminologies which you need to understand first before you start understanding AWS deeply.

If you visit AWS global infrastructure page, it shows list of regions with count of availability zones under it. The AWS cloud operates 58 availibility zones with 18 geographic regions around the world, with 12 more availibility zone and 4 more regions coming online throughout the next year.

What is AWS Region?

Region is physical location in the world where AWS resource exists, they have more then one availability zones.

What is AWS Global Infrastructure?
AWS Global Infrastructure?


What is AWS Availability Zone?

Availibility zone (AZ) consits one or more data center in given region. Data centers are designed with redundant power, networking & connectivity.

What is AWS Regions and Availability Zones?
List of AWS Regions and Availibility Zones


What is AWS Edge Location?

Edge Location is CDN (content delivery network) end points for cloud front place where data is cached. Edge Locations are deployed worldwide in major cities to reduce latency issue.
Read more »

How to wrap text in crystal report?

How to wrap text in crystal report?

You might be facing fields overlapping or cuts off issue. You can show text up to width of IFieldObject/ITextObject contol's length, IFieldObject control is similar to Label/Textbox in ASP.Net.

You might have question that, does crystal report supports word wrapping ?
Answer is NO.

But, As an alternative of it is you can allow it to grow in multiline. For that crystal report supports "Can Grow" property for fields in which text is overlapping.

Please follow the below mentioned steps to set:
1. Open Cystal report .rpt file in Visual studio
2. Select the field which is overlapping, Right click on that and select "Format Object" option.
3. It will open new window, under "Common" tab, mark the "Can Grow" checkbox.
Crystal Report -> Format Object -> Can Grow

4. In case you want to limit text grow up to some lines, you can mention total number of lines in "Maximum number of lines" textbox. Here 0 will be considered as no limit.
Crystal Report -> Format Object -> Can Grow -> maximum Number of Lines

5. Also drag & stretch the field to set the height based on your requirement. That's it.
Read more »