Showing posts with label following. Show all posts
Showing posts with label following. 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
}
Subscribe to:
Posts (Atom)