Showing posts with label print. Show all posts
Showing posts with label print. Show all posts

Saturday, February 14, 2015

Java program to print fibonacci series

Java program to print fibonacci series

class Fibonacci
{
public static void main(String...s)
{
int first=0,second=1,third,n,i;
n=Integer.parseInt(s[0]);

System.out.print("
"+first+" "+second);

for(i=2;i<n;i++)
{
third=first+second;
first=second;
second=third;
System.out.print(" "+third);
}
System.out.println();
}
}
Read more »

Thursday, February 12, 2015

C Program to Print Heart Shape With Happy Friendship Day Message Inside it

On this special day I thought to share something unique. So here is the program to print heart shape with happy friendship day message inside it. You can give this as a gift to your programmer friend. If you like it, dont forget to share it!

Also Read: C Program to Print India Map

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    double x, y, size=10;
    char ch=3;
    string message(" Happy Friendship Day ");
    int print_line = 4;

    if (message.length() % 2 != 0) message += " ";

    for (x=0;x<size;x++)
    {
        for (y=0;y<=4*size;y++)
        {
            double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) );
            double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) );

            if (dist1 < size + 0.5 || dist2 < size + 0.5 ) {
                cout << ch;
            }
            else cout << " ";
        }
        cout<<"
";

    }

    for (x=1;x<2*size;x++)
    {
        for(y=0;y<x;y++) cout << " ";

        for (y=0; y<4*size + 1 - 2*x; y++)
        {
            if (x >= print_line - 1 && x <= print_line + 1) {
                int idx = y - (4*size - 2*x - message.length()) / 2;
                if (idx < message.length() && idx >= 0) {
                    if (x == print_line) cout<<message[idx];
                    else cout << " ";
                }
                else cout << ch;
            }
            else cout << ch;
        }
        cout<<endl;
    }
    return 0;
}

C++ Program to Print Heart Shape With Happy Friendship Day Message inside it

Source: http://stackoverflow.com/questions/20075775/print-heart-shape-with-words-inside
Read more »