1
2 4
1 3 5
2 4 6 8
1 3 5 7 9
#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
if(i%2==0)
{
k=2;
}
else
{
k=1;
}
for(j=1;j<=i;j++,k+=2)
{
printf("%d ", k);
}
printf("\n");
}
return 0;
}
Related Links:
- More Number Pattern Programs
- Star Pattern Programs in C
- Alphabet Pattern Programs in C
- Series Programs in C
nice approach.
ReplyDeletevoid main()
ReplyDelete{ clrscr();
int i,j;
for(i=1;i<=5;i++)
{ if(i%2==1)
{ for(j=1;j<=i*2;j=j+2)
printf("%d",j);
}
else
{ for(j=2;j<=i*2;j=j+2)
printf("%d",j);
}
printf("\n");
}
getch();
}
Int main()
ReplyDelete{
Int I, j;
For(i=1;i<=5;i++)
{
For(j=1;j<=i;j++)
{
If(i%2==0)
{
Pf("%d",2j);
}
Else
{
Pf("%d",2j-1);
}
}
Pf("\n");
}
Return 0 ;
}
could not understand line 15. but the code is pretty correct.
ReplyDeletekoi java me code likho vai...
ReplyDeletepublic class Shape
Delete{
public static void main() {
for(int i = 1;i <= 5;i++) {
int k = 0;
if(i % 2 == 0) {
k = 2;
}
else {
k = 1;
}
for(int j = k;j <= (2*i);j+=2) {
System.out.print(j+" ");
}
System.out.println();
}
}
}
Here you go... lol
#include
ReplyDeleteint main ()
{
int i,j,n,k;
printf ("Enter the value of n:");
scanf ("%d",&n);
for (i=1;i<=n;i++)
{
if(i%2==1)
k=-1;
else
k=0;
for (j=1;j<=i;j++)
{
printf ("%d",k+=2);
}
printf ("\n");
}
}
#include
ReplyDeleteint main()
{
int r,i,j;
printf("Enter the no. of rows : ");
scanf("%d",&r);
for(i=1;i<=r;i++)
{
for(j=(i+1)%2+1;j<=(2*i)-(i%2);j+=2)
{
printf("%d ",j);
}
printf("\n");
}
}
#include
ReplyDeletevoid main()
{
int i,j;
for(i=1;i<=9;(i%2 != 0)?i+=3:i++)
{
if(i%2 != 0)
{
for(j=1;j<=i;j+=2)
{
printf("%d",j);
}
}
else
{
for(j=2;j<=i;j+=2)
{
printf("%d",j);
}
}
printf("\n");
}
}