Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Wednesday, April 9, 2014

Rectangle number pyramid

Q. Write a C program for print the following number design or number pyramid or number rectangle:

33333
32223
32123
32223
33333

Ans.

To make the above program make module/program and add all module(tips):
Make 3 parts of the design and write down code and at the end, add all parts/module
Figure: How to write above program tips


/*c program for print number rectangle pyramid*/
#include<stdio.h>
int main()
{
 int i,j,k,n=3,r;
 for(j=1; j<=5; j++)
    printf("%d",n);
 printf("
"
);

 for(r=1; r<=3; r++)
 {
  for(i=3; i>=2; i--)
    printf("%d", i);
  for(k=n-r; k>=0; k--)
  {
    if(k==0)
      printf("2");
    else
    {
      printf("%d",k);
      break;
    }
  }
  for(i=2; i<=3; i++)
     printf("%d",i);
  printf("
"
);

 }
 for(j=1; j<=5; j++)
     printf("%d",n);
 return 0;
}

The output of above program would be:
Output of rectangle number pyramid C program
Screen shot for rectangle number pyramid C program


Read More..

Monday, April 7, 2014

Square Number Triangle

Q. Write a C program to print the following square number triangle as:

1
1 4 9
1 4 9 16 25
1 4 9 16 25 36 49
1 4 9 16 25 36 49 64 81

Ans.

/*c program for square number triangle*/
#include<stdio.h>
int main()
{

 int r,c,q=1;
 for(r=1; r<=5; r++,q=q+2)
 {
  for(c=1; c<=q; c++)
     printf(" %d",c*c);
  printf("
"
);
 }
 getch();
 return 0;
}

/***********************************************************
The output of above program would be:
***********************************************************/

Output of square number triangle C program
Figure: Screen shot for square number triangle C program

Related Program:


1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9 
Read More..

Sunday, April 6, 2014

Number pattern

Q. Write a C program to display the following pattern:
 1
 2   3
 4   5    6
 7   8    9    10
11  12   13    14  15

Ans.

/*program to design the above pattern*/
#include<stdio.h>
#include<conio.h>
void main()
{
 int r,c,n=1;
 clrscr();
 for(r=1; r<=5; r++)
 {
  for(c=1; c<=r; r++)
  {
    printf("%3d",n++);
  }
  printf("
"
);
 }
 getch();
}

Output:-

 1
 2   3
 4   5    6
 7   8    9    10
11  12   13    14  15
Read More..
 
Copyright 2009 Information Blog
Powered By Blogger