9.02.2011

6.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)

                        12345
                        12345
                        12345
                        12345
                        12345

Ans.

/* c program for number rectangle*/
#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("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}

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

                        12345
                        12345
                        12345
                        12345
                        12345

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

9.01.2011

5.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,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("@");
  printf("\n");
 }
 getch();
 return 0;
}
/*************OUTPUT**************
Enter loop repeat number(rows): 5





@



@@


@@@

@@@@
@@@@@

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

4.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,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(r=1; num>=r; r++)
 {
  for(c=1; c<=r; c++)
     printf("#");
  printf("\n");
 }
 getch();
 return 0;
}

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

#



##


###

####
#####

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

3.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,c;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 for(; num>=1; num--)
 {
  for(c=1; c<=num; c++)
     printf("@");
  printf("\n");
 }
 getch();
 return 0;
}

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

@@@@@
@@@@
@@@

@@


@

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

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

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

Calculate power of number

Q. Write a program to calculate power of particular number?
Example: 54=625

Ans.

/* c program for calculator power of number*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,pow,res=1;
 printf("\nEnter number and power : ");
 scanf("%d %d",&num,&pow);
 while(pow>=1)
 {
  res=res*num;
  pow--;
 }
 printf("%d",res);
 return 0;
}

/************ OUTPUT **************
Enter number and power : 5
4
625
**********************************/