Q. Write a C program to print the following even odd number star pyramid as:
1
*2
1*3
*2*4
1*3*5
*2*4*6
Ans.
/*odd even number star pyramid C program*/
#include<stdio.h>
int main()
{
int num,r,c,z;
printf("Enter no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1,z=r; c<=r; c++,z--)
{
if(z%2==0)
printf("%d",c);
else
printf("*");
}
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
1
*2
1*3
*2*4
1*3*5
*2*4*6
Ans.
/*odd even number star pyramid C program*/
#include<stdio.h>
int main()
{
int num,r,c,z;
printf("Enter no. of rows : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(c=1,z=r; c<=r; c++,z--)
{
if(z%2==0)
printf("%d",c);
else
printf("*");
}
printf("\n");
}
getch();
return 0;
}
The output of above program would be:
Figure: Screen shot for odd even number star pyramid C program |
1
ReplyDelete3*2
4*5*6
10*9*8*7
11*12*13*14*15
please send me code...its urgent
its java code you have to convert it in c
Deletepackage Triangle;
import java.util.Scanner;
public class Prg48 {
/**
* @param args
*/
public static void main(String[] args) {
int i,j,no,d=1,c=1;
Scanner sc = new Scanner(System.in);
no = sc.nextInt();
for(i=1;i<=no;i++)
{
if(i%2==0)
{
c=c+i;
d=c+1;
if(i>2)
{
c=c*2;
d=c+1;
}
for(j=1;j<=i*2-1;j++)
{
if(j%2==0)
{
System.out.print("*");
}
else
{
System.out.print(c);
c--;
}
}
System.out.println();
}
else
{
for(j=1;j<=i*2-1;j++)
{
if(j%2==0)
{
System.out.print("*");
}
else
{
System.out.print(d);
d++;
}
}
System.out.println();
}
}
}
// TODO Auto-generated method stub
}
*
ReplyDelete* * *
* * * * *
please provide program for this star pattern?
@ Arundhati Saxena,
DeleteYour required star pattern C program source code as:
http://cprogrammingcodes.blogspot.com/2012/10/star-pyramid-pattern.html
Plz print
ReplyDelete××××××
×××
×
Your required symbol hash pattern C program source code as:
Delete#include"stdio.h>
int main()
{
int n=6,r,c;
for(r=1; r<=3; r++,n=n-3)
{
for(c=1; c<=n; c++)
printf("*");
printf("\n");
}
printf("#");
getch();
return 0;
}
/****************Output****************/
######
###
#
Plz print
ReplyDelete×××××
×××
×
Plz print
ReplyDelete×
×××
×
print the pattern
ReplyDelete*
* *
* * *
* * * *
Symbol pattern C program source code as:
Deletehttp://cprogrammingcodes.blogspot.com/2011/09/4design-tringle-praymid.html