Showing posts with label mca/bca assignment. Show all posts
Showing posts with label mca/bca assignment. Show all posts

Saturday, 3 September 2011

19.Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)

1 2 3 4 5 4 3 2 1
2 3 4 5 4 3 2
3 4 5 4 3
4 5 4
5
Ans.
/* c program for number structure */
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c,sp;
 printf("Enter loop repeat number : ");
 scanf("%d",&num);
 for(r=1; r<=num; r++)
 {
   for(sp=r; sp>1; sp--)
      printf(" ");
   for(c=r; c<=num; c++)
      printf("%d",c);
   for(c=num-1; c>=r; c--)
      printf("%d",c);
   printf("\n");
 }
 getch():
 return 0;
}
/************** OUTPUT *************
Enter loop repeat number : 5

123454321
2345432
34543
454

5
***********************************/

18. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)

1 2 3 4 5 4 3 2 1

1 2 3 4 3 2 1


1 2 3 2 1




1 2 1






1

Ans.
/*c program for number triangle pyramid*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r=1,c,sp,x;
 printf("Enter loop repeat number(rows):");
 scanf("%d",&num);
 for(; num>=1; num--,r++)
 {
   for(sp=r; sp>1; sp--)
      printf(" ");
   for(c=1; c<=num; c++)
      printf("%d",c);
   for(x=num-1; x>=1; x--)
      printf("%d",x);
   printf("\n");
 }
 getch();
 return 0;
}
/****************OUTPUT************
Enter loop repeat number(rows): 5

123454321

1234321


12321




121






1

************************************/

Friday, 2 September 2011

17. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
1






1 2 1




1 2 3 2 1


1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1

Ans.
/*c program for number triangle pyramid*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c,sp,x;
 printf("Enter loop repeat number(rows):");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
   for(sp=num-r; sp>=1; sp--)
      printf(" ");
   for(c=1; c<=r; c++)
      printf("%d",c);
   for(x=r-1; x>=1; x--)
      printf("%d",x);
   printf("\n");
 }
 getch();
 return 0;
}
/****************OUTPUT***************
Enter loop repeat number(rows): 5

1






121




12321


1234321
123454321

**************************************/

16. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)

1 2 3 4 5

1 2 3 4


1 2 3



1 2




1

Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r=1,c,sp;
 printf("Enter loop repeat number(rows):");
 scanf("%d",&num);
 for(; num>=1; num--,r++)
 {
  for(sp=r; sp>1; sp--)
     printf(" ");
  for(c=1; c<=num; c++)
     printf("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}
/****************OUTPUT***********
Enter loop repeat number(rows): 5

12345

1234


123



12




1

********************************/

15. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)

                            12345
                            1234
                            123
                            12
                            1
                           
Ans.
/*c program for number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(; num>=1; num--)
 {
   for(c=1; c<=num; c++)
      printf("%d",c);
   printf("\n");
 }
 getch();
 return 0;
}
/****************OUTPUT*********** 
Enter loop repeat number(rows): 5

                            12345
                            1234
                            123
                            12
                            1

********************************/

14. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)
                       
                        1
                        21
                        321
                        4321
                        54321

Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,c,r;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(c=r; c>=1; c--)
     printf("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}

/*************OUTPUT****************
Enter loop repeat number(rows): 5

                        1
                        21
                        321
                        4321
                        54321

************************************/

13. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:(Where user entered number through keyboard, for example if num=5)

                            54321
                            4321
                            321
                            21
                            1
Ans.
/*c program for number triangle pyramid*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(; num>=1; num--)
 {
  for(c=num; c>=1; c--)
     printf("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}

/*************OUTPUT****************
Enter loop repeat number(rows): 5

                            54321
                            4321
                            321
                            21
                            1

************************************/

Thursday, 1 September 2011

12. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:
   (Where user entered number through keyboard, for example if num=5).
      




1



1 2


1 2 3

1 2 3 4
1 2 3 4 5
Ans.
/*c program for number triangle pyramid*/

#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c,sp;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(sp=num-r; sp>=1; sp--)
     printf(" ");
  for(c=1; c<=r; c++)
     printf("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}

/*************OUTPUT****************
Enter loop repeat number(rows): 5





1



12


123

1234
12345

************************************/

11.Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:
   (Where user entered number through keyboard, for example if num=5)

                                12345
                                1234
                                123
                                12
                                1
Ans.
/*c program for number triangle pyramid*/
#include<stdio.h>

#include<conio.h>
int main()
{
 int num,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(; num>=1; num--)
 {
  for(c=1; c<=num; c++)
     printf("%d",c);
  printf("\n");
 }
 return 0;
}

/*************OUTPUT****************
Enter loop repeat number(rows): 5

                                12345
                                1234
                                123
                                12
                                1

*********************************/

10. Design numbers tringle pyramid

Q. Write a program to generate a following numbers triangle:
   (Where user entered number through keyboard, for example if num=5)

                        1
                        12
                        123
                        1234
                        12345
Ans.

/* c program for number triangle*/
#include<stdio.h>
//#include<conio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; r<=num; r++)
 {
  for(c=1; c<=r; c++)
     printf("%d",c);
  printf("\n");
 }
 //getch();
 return 0;
}

/*************OUTPUT**************
Enter loop repeat number(rows): 5

                        1
                        12
                        123
                        1234
                        12345

***********************************/

9.Design numbers rectangle structure

Q. Write a program to generate a following numbers structure:
   (Where user entered number through keyboard, for example if num=5)
                            11111
                            22222
                            33333
                            44444
                            55555
                           
Ans.


#include<stdio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(c=num; c>=1; c--)
     printf("%d",r);
  printf("\n");
 }
 return 0;
}

/*************OUTPUT****************
Enter loop repeat number(rows): 5

                            11111
                            22222
                            33333
                            44444
                            55555

************************************/

2. Design triangle pyramid

Q. Write a program to generate a following #'s triangle?

# # # # #

# # # #


# # #



# #




#

Ans.

/* c program for symbol triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r=1,c,sp;
 printf("Enter loop repeat number(rows): "); 
 scanf("%d",&num);
 for(; num>=1; num--,r++)
 {
  for(sp=r; sp>1; sp--)
     printf(" ");
  for(c=1; c<=num; c++)
    printf("#");
  printf("\n");
 }
 getch();
 return 0;
}

/*************OUTPUT**************
Enter loop repeat number(rows): 5
#####
 ####
  ###
   ##
    #
***********************************/

1. Design rectangle pyramid

Q. Write a program to generate a following structure?
               
                @@@@@
                @@@@@
                @@@@@
                @@@@@
                @@@@@
               
Ans.   

/* c program for symbol structure*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,r,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(c=1; c<=num; c++)
     printf("@");
  printf("\n");
 }
 getch();
 return 0;
}

/************* OUTPUT **************
Enter loop repeat number(rows): 5

                @@@@@
                @@@@@
                @@@@@
                @@@@@
                @@@@@
***********************************/