Showing posts with label print. Show all posts
Showing posts with label print. Show all posts
Tuesday, February 17, 2015
C program to print following square using character
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr(); //to clear the screen
printf("Enter size of the square:");
scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("
");
");
for(j=0;j<n;++j)
{
if(i==0||i==n-1||j==0||j==n-1)
printf("*");
else
printf(" ");
}
}
getch(); //to stop the screen
}
Friday, February 13, 2015
C program to print the following pattern

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr(); //to clear the screen
int i,j,k,n;
cout<<"How many lines?";
cin>>n;
n*=2;
for(i=0;i<n;i+=2)
{
cout<<"
";
for(j=n;j>i;j-=2)
cout<<" ";
for(k=0;k<=i;++k)
cout<<"*";
}
getch(); //to stop the screen
}
Wednesday, February 11, 2015
My First Java Program Print a Message Hello World

class HelloWorld
{
public static void main(String...s)
{
System.out.println("Hello World");
}
}
Tuesday, February 10, 2015
Valentine’s Day Special C Program to Print Heart Shape with Happy Valentine’s Day Message inside it
Today’s day is very special for all lovers. So I thought that I should share some programming stuff that show Valentine’s Day felling. A C++ program is given below which prints heart shape with a Happy Valentine’s Day message inside it. If you want, you can change the message by changing the value of string message. I hope that you will like this.

Also Read: Simple program to create a moving car in graphics
Also Read: Simple program to create a circular loading bar using graphics
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x, y, size=10;
char ch=3;
string message(" Happy Valentines 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;
return 0;
}
Subscribe to:
Posts (Atom)