Tuesday 18 September 2012

Q. Write a program to generate a following numbers triangle:


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

123454321
 2345432
  34543
   454
    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;
}

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

123454321
 1234321
  12321
   121
    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;
}
case2:
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
   121
  12321
 1234321
123454321

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
case3:
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)

12345
1234
 123
  12
   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

********************************/
case4:
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

********************************/
case5:
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

************************************/
case6:
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

************************************/
case7:
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
      12
     123
    1234
   12345
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

************************************/
case8:
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

*********************************/
case9:
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>
#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=num; c>=1; c--)
     printf("%d",r);
  printf("\n");
 }
 getch();
 return 0;
}
/*************OUTPUT****************
Enter loop repeat number(rows): 5

                            11111
                            22222
                            33333
                            44444
                            55555

************************************/
case10:
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; num>=r; 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

***********************************/
case11:
8.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)
                            55555
                            44444
                            33333
                            22222
                            11111

Ans.

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

                            55555
                            44444
                            33333
                            22222
                            11111

***********************************/  
case12:
7.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)

                                54321
                                54321
                                54321
                                54321
                                54321

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

                                54321
                                54321
                                54321
                                54321
                                54321

***********************************/
case13:
           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

***********************************/
case14:
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

#
##
###
####
#####

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

case15:
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





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

***********************************/
case16:
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

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

***********************************/
case17:
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
#####
 ####
  ###
   ##
    #
***********************************/
case18:
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

                @@@@@
                @@@@@
                @@@@@
                @@@@@
                @@@@@
***********************************/
case19:
Q. Write a c program for following number structure :
1
22
333
4444
55555
4444
333
22
1

Ans.

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

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


Output :-

Enter triangle number :5
1
22
333
4444
55555
4444
333
22
1
case20:
Pyramid triangle
Q. Write a C program for following structure:


9
0 1
2 3 4
5 6 7 8
9 0 1 2 3


Ans.


/*c program for triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int i,c,r,x=0,n=4;
 printf("9\n");
 for(r=1; n>=r; r++)
 {
  for(c=0; c<=r; c++,x++)
  {
   if(x<10)
     printf("%d ",x);
   else
   {
     for(i=0; i<=3; i++)
        printf("%d ",i);
     break;
   }
  }
  printf("\n");
 }
 getch();
 return 0;
}
case21;
Q. Write a C program to print the following number triangle:


1
12
123
1234
12345
1234
123
12
1


Ans.


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

case22:
Q. Write a C program to print the following number structure:


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


Ans.


/*c program for print the following number triangle*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,sp,n=6;
 for(r=1; r<=6; r++)
 {
  for(sp=1; sp<=n; sp++)
     printf(" ");
  for(c=1; c<=r; c++)
  {
     printf("%d",r);
     printf(" ");
  }
  printf("\n");
  n=n-1;
 }
 getch();
 return 0;
}
case23:
Q. Write a C program to print the following number triangle or number structure:


           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


Ans.


/*c program for above number triangle codes*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int r,c,sp,num;
 printf("Enter loop repeat number(rows): ");
 scanf("%d", &num);
 for(r=1; r<=num; r++)
 {
  for(sp=1; sp<=num-r; sp++)
     printf("  ");   //it is 2 blank space
  for(c=1; c<=2*r-1; c++)
     printf(" %d",c);
  printf("\n");
 }
 getch();
 return 0;
}
case24:
Q. Write a C program to print the following number structure:


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


Ans.


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

case25:
Q. Write a C program to display the following number structure:


1234554321
1234__4321
123____321
12______21
1________1


Ans.


/* c program for number rectangle or number pyramid*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,c,sp,r=1;
 printf("Enter loop repeat number(rows): ");
 scanf("%d",&num);
 printf("\n");
 for(; num>=1; num--,r++)
 {
  for(c=1; c<=num; c++)
     printf("%d",c);
  for(sp=r; sp>1; sp--)
     printf("_");
  for(sp=r; sp>1; sp--)
     printf("_");
  for(c=num; c>=1; c--)
     printf("%d",c);
  printf("\n");
 }
 getch();
 return 0;
}
case26:
Q. Write a C program to print the following number triangle or structure:


     1
    21
   321
  4321
 54321


Ans.


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

case27:
Q. Write a C program to print the following number pyramid:


54321
 4321
  321
   21
    1


Ans.


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

Monday 17 September 2012

C program to find hcf and lcm:


DESCRIPTION:
The code below finds highest common factor and least common
multiple of two integers. HCF is also known as
greatest common divisor(GCD) or greatest common factor(gcf).
CODE:
C programming code
#include <stdio.h>

int main() {
  int a, b, x, y, t, gcd, lcm;

  printf("Enter two integers\n");
  scanf("%d%d", &x, &y);

  a = x;
  b = y;

  while (b != 0) {
    t = b;
    b = a % b;
    a = t;
  }

  gcd = a;
  lcm = (x*y)/gcd;

  printf("Greatest common divisor of %d and %d = %d\n", x, y, gcd);
  printf("Least common multiple of %d and %d = %d\n", x, y, lcm);

  return 0;
}
C program to find hcf and lcm using recursion
#include <stdio.h>

long gcd(long, long);

int main() {
  long x, y, hcf, lcm;

  printf("Enter two integers\n");
  scanf("%ld%ld", &x, &y);

  hcf = gcd(x, y);
  lcm = (x*y)/hcf;

  printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf);
  printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm);

  return 0;
}

long gcd(long a, long b) {
  if (b == 0) {
    return a;
  }
  else {
    return gcd(b, a % b);
  }
}
C program to find hcf and lcm using function
#include <stdio.h>

long gcd(long, long);

int main() {
  long x, y, hcf, lcm;

  printf("Enter two integers\n");
  scanf("%ld%ld", &x, &y);

  hcf = gcd(x, y);
  lcm = (x*y)/hcf;

  printf("Greatest common divisor of %ld and %ld = %ld\n", x, y, hcf);
  printf("Least common multiple of %ld and %ld = %ld\n", x, y, lcm);

  return 0;
}

long gcd(long x, long y) {
  if (x == 0) {
    return y;
  }

  while (y != 0) {
    if (x > y) {
      x = x - y;
    }
    else {
      y = y - x;
    }
  }

  return x;
}
OUTPUT:
ENTER TWO INTEGERS:
9 15
GREATEST COMMON DIVISOR OF 9 AND 15= 3
LEAST COMMON MULTIPLE OF 9 AND 15=45

c program to check leap year




DESCRIPTION:
c program to check leap year: c code to check leap year,
year will be entered by the user. Please read the leap year
article before reading the code, it will help you to understand the program.
C programming code
#include <stdio.h>

int main()
{
  int year;

  printf("Enter a year to check if it is a leap year\n");
  scanf("%d", &year);

  if ( year%400 == 0)
    printf("%d is a leap year.\n", year);
  else if ( year%100 == 0)
    printf("%d is not a leap year.\n", year);
  else if ( year%4 == 0 )
    printf("%d is a leap year.\n", year);
  else
    printf("%d is not a leap year.\n", year);

  return 0;
}
OUTPUT
ENTER A YEAR TO CHECK IF IT IS A LEAP YEAR:
2012
2012 IS A LEAP YEAR

c program to print Floyd's triangle



DESCRIPTION:
C program to print Floyd's triangle:- This program prints Floyd's triangle. Number of rows of Floyd's triangle to print is entered by the user. First four rows of Floyd's triangle are as follows :-
1
2 3
4 5 6
7 8 9 10
It's clear that in Floyd's triangle nth row contains n numbers.
code;
#include <stdio.h>

int main()
{
  int n, i,  c, a = 1;

  printf("Enter the number of rows of Floyd's triangle to print\n");
  scanf("%d", &n);

  for (i = 1; i <= n; i++)
  {
    for (c = 1; c <= i; c++)
    {
      printf("%d ",a);
      a++;
    }
    printf("\n");
  }

  return 0;
}
output:
enter the no of rows of floyds triangle to print:
5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
case1:
#include<stdio.h>

main()
{
    int c, n, k;
    char ch = 'A';


    printf("Enter number of rows\n");
    scanf("%d",&n);

    for ( c = 1 ; c <= n ; c++ )
    {
        for ( k = 1 ; k <= c ; k++)
            printf("%c ", ch);

        printf("\n");
        ch++;
    }

    return 0;
}
output:
A
BB
CCC
DDDD
EEEEEE
CASE2:
#include<stdio.h>

main()
{
   int n, c, k, space = 0;
   char ch, temp;

   scanf("%d", &n);

   ch = 'A'+n-1;
   temp = ch;

   for ( k = n ; k >= 1 ; k-- )
   {
      for ( c = 1 ; c <= space; c++)
         printf(" ");

      space++;

      for ( c = 1 ; c <= k ; c++ )
      {
         printf("%c",temp);
         temp--;
      }

      printf("\n");
      ch--;
      temp = ch;
   }

   return 0;
}
OUTPUT:
EDCBA
 DCBA
  CBA
   BA
    A

c program to generate and print armstrong numbers


DESCRIPTION:
armstrong number in c: This program prints armstrong number. In our program we ask the user to enter a number and then we use a loop from one to the entered number and check if it is an armstrong number and if it is then the number is printed on the screen. Remember a number is armstrong if the sum of cubes of individual digits of a number is equal to the number itself. For example 371 is an armstrong number as 33 + 73 + 13 = 371. Some other armstrong numbers are 0, 1, 153, 370, 407.
C code
#include<stdio.h>
#include<conio.h>

main()
{
   int r;
   long number = 0, c, sum = 0, temp;

   printf("Enter the maximum range upto which you want to find armstrong numbers ");
   scanf("%ld",&number);

   printf("Following armstrong numbers are found from 1 to %ld\n",number);

   for( c = 1 ; c <= number ; c++ )
   {
      temp = c;
      while( temp != 0 )
      {
         r = temp%10;
         sum = sum + r*r*r;
         temp = temp/10;
      }
      if ( c == sum )
         printf("%ld\n", c);
      sum = 0;
   }

   getch();
   return 0;
}
Armstrong number program executable.
OUTPUT;
Enter the maximum range upto which you want to find armstrong numbers1000
 Following armstrong numbers are found from 1 to 1000
1
153
370
371
407
purpose of returning zero

Every c program begins with function main,
and main is called by operating system of your computer .
 So we return a value to os indicating whether our program
has successfully executed or an error has occurred. Returning zero
indicates success i.e. program has been executed successfully.armstrong number c program
.CASE1:
armstrong number c program: c programming code to check
whether a number is armstrong or not
DESCRIPTION:
 A number is armstrong
if the sum of cubes of individual digits of a number
is equal to the number itself. For example 371 is an
armstrong number as 33 + 73 + 13 = 371.
Some other armstrong numbers are: 0, 1, 153, 370, 407.
C programming code
#include <stdio.h>

main()
{
   int number, sum = 0, temp, remainder;

   printf("Enter a number\n");    
   scanf("%d",&number);

   temp = number;

   while( temp != 0 )
   {
      remainder = temp%10;
      sum = sum + remainder*remainder*remainder;
      temp = temp/10;
   }

   if ( number == sum )
      printf("Entered number is an armstrong number.");
   else
      printf("Entered number is not an armstrong number.");        

   return 0;
}
OUTPUT;
ENTER A NUMBER
407
ENTER NUMBER IS AN ARMSTRONG NUMBER

anagram in c


DESCRIPTION;
Anagram in c: c program to check whether two strings are anagrams or not, string is assumed to consist of alphabets only. Two words are said to be anagrams of each other if the letters from one word can be rearranged to form the other word. From the above definition it is clear that two strings are anagrams if all characters in both strings occur same number of times. For example "abc" and "cab" are anagram strings, here every character 'a', 'b' and 'c' occur only one time in both strings. Our algorithm tries to find how many times characters appears in the strings and then comparing their corresponding counts.
PROGRAM
C anagram programming code
#include <stdio.h>

int check_anagram(char [], char []);

int main()
{
   char a[100], b[100];
   int flag;

   printf("Enter first string\n");
   gets(a);

   printf("Enter second string\n");
   gets(b);

   flag = check_anagram(a, b);

   if (flag == 1)
      printf("\"%s\" and \"%s\" are anagrams.\n", a, b);
   else
      printf("\"%s\" and \"%s\" are not anagrams.\n", a, b);

   return 0;
}

int check_anagram(char a[], char b[])
{
   int first[26] = {0}, second[26] = {0}, c = 0;

   while (a[c] != '\0')
   {
      first[a[c]-'a']++;
      c++;
   }

   c = 0;

   while (b[c] != '\0')
   {
      second[b[c]-'a']++;
      c++;
   }

   for (c = 0; c < 26; c++)
   {
      if (first[c] != second[c])
         return 0;
   }

   return 1;
}
OUTPUT:
ENTER THE FIRST STRING
CARE
ENTER SECOND STRING
RACE
"CARE" AND "RACE" ARE ANAGRAMS

Pascal Triangle in c:


DESCRIPTION:
Pascal Triangle in c: C program to print Pascal triangle which you might have studied in Binomial Theorem in Mathematics. Number of rows of Pascal triangle to print is entered by the user. First four rows of Pascal triangle are shown below :-

   1
  1 1
 1 2 1
1 3 3 1
PROGRAM:
Pascal triangle in c
#include<stdio.h>

long factorial(int);

main()
{
   int i, n, c;

   printf("Enter the number of rows you wish to see in pascal triangle\n");
   scanf("%d",&n);

   for ( i = 0 ; i < n ; i++ )
   {
      for ( c = 0 ; c <= ( n - i - 2 ) ; c++ )
         printf(" ");

      for( c = 0 ; c <= i ; c++ )
         printf("%ld ",factorial(i)/(factorial(c)*factorial(i-c)));

      printf("\n");
   }

   return 0;
}

long factorial(int n)
{
   int c;
   long result = 1;

   for( c = 1 ; c <= n ; c++ )
         result = result*c;

   return ( result );
}
ENTER THE NUMBER OF ROWS YOU WISH TO SEE IN PASCAL TRIANGLE5
      1
     1 1
    1 2 1
   1 3 3 1
  1 4 6 4 1
source code of pattern below:

   1
  121
 12321
1234321 
#include<stdio.h>

main()
{
    int n, c, k, number = 1, space = n;

    printf("Enter number of rows\n");
    scanf("%d",&n);

    space = n;

    for ( c = 1 ; c <= n ; c++ )
    {
        for ( k = space ; k > 1 ; k-- )
            printf(" ");

        space--;

        for ( k = 1 ; k <= 2*c - 1 ; k++ )
        {
            if ( k <= c)
            {
                 printf("%d", number);

                 if ( k < c )
                 number++;
            }
            else
            {
                number--;
                printf("%d", number);
            }
        }

        number = 1;
        printf("\n");
    }

    return 0;
}