How to print this -
1
12
234
3456
45678
#include<stdio.h>
#include<conio.h>
int main()
{
int row,column,x;
for(row=1;row<=5;row++)
{
for(column=1;column<row+1;column++)
{
x=row+column-2;
if(x==0)
printf("1");
else
printf("%d",x);
}
printf("\n");
}
}
Code is 100% working.
Compiled with GCC 4.6.1 with -std=c99 option enabled.
IDE = orwell Dev-C++ v5.2.0.3
Coding with C
Friday, 2 November 2012
Print a Pattern - #1
How to print this -
Question- Write a complete C program to print the following pattern for n number of rows, where n is supplied externally,
* *
** **
*** ***
**** ****
*********
#include<stdio.h>
#include<conio.h>
int main()
{
int n,star=0,space,width,i,j;
printf("ENTER LENGTH: ");
scanf("%d",&n);
n+=1;
width=(n*2)-4;
for(i=0;i<n;i++)
{
space=width-star*2;
for(j=0;j<width+1;j++)
{
if(j<star||j>(star+space))
printf("*");
else
printf(" ");
}
printf("\n");
star++;
}
}
Code is 100% working.
Compiled with GCC 4.6.1 with -std=c99 option enabled.
IDE = orwell Dev-C++ v5.2.0.3
Subscribe to:
Comments (Atom)
