8.02.2012

print Armstrong number range

Q. Write a C program to accept a number from user and print all the Armstrong number that are less then or equal to user number.
or
Q. write a C program to print Armstrong number from 1 to 1000.

Ans.

/*C program to printing armstrong number between a specific range*/
#include<stdio.h>
#include<conio.h>
int main()
{
 int num,d1,d2,d3,tmp,st;
 printf("Enter ending number: ");
 scanf("%d", &num);
 for(st=1; st<=num; st++)
 {
  d1=st-((st/10)*10);
  d2=(st/10)-((st/100)*10);
  d3=(st/100)-((st/1000)*10);
  tmp=(d1*d1*d1)+(d2*d2*d2)+(d3*d3*d3);
  if(tmp==st)
     printf("\nArmstrong number is: %d",tmp);
 }
 getch();
 return 0;
}

/************Output************/


Output for print aremstrong number 1 to 786 C program
Screen shot for print aremstrong number to a specific range

Related Programs:

  1. Search Armstrong number C program
  2. Flowchart for check a number is Armstrong or not
  3. Amicable number C program
  4. Perfect number C program

Convert Fahrenheit to Celsius

Q. Write a C program to convert Fahrenheit to Celsius temp temperature.
or
Q. Write a C program to accept temperature in Fahrenheit  from user and convert into the Celsius.


Ans.


/*C program to convert Fahrenheit to Celsius*/
/*Formula(Fahrenheit to Celsius):
Celsius = (Fahrenheit - 32) / 1.8
*/
#include<stdio.h>
#include<conio.h>
int main()
{
 float fh,cl;
 printf("Enter temperature value in Fahrenheit: ");
 scanf("%f", &fh);
 cl = (fh - 32) / 1.8;
 printf("Converted Celsius value: %f",cl);
 getch();
 return 0;
}


/************Output************/


Output of convert temperature from Fahrenheit to Celsius C program
Screen shot for convert temperature from Fahrenheit to celsius

Related program:
  1. Convert Celsius to Fahrenheit

8.01.2012

Convert Celsius to Fahrenheit

Q. Write a C program to convert temperature  Celsius to Fahrenheit.


Ans.


/*c program to convert Celsius to Fahrenheit temperature*/
#include<stdio.h>
#include<conio.h>
int main()
{
 float fh,cl;
 printf("Enter temperature value in Celsius: ");
 scanf("%f", &cl);
 /*convert formula: Fahrenheit to Celsius*/
 fh = (1.8*cl) + 32;
 printf("Converted Fahrenheit value: %f",fh);
 getch();
 return 0;
}


/************Output************/


Output of convert temperature Celsius to Fahrenheit C program
Screen shot for converting temperature
Celsius to Fahrenheit


Related programs:

  1. Convert Fahrenheit to Celsius

7.28.2012

Number triangle

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;
}


/**************Output**************/


Output of number pyramid C program
Screen shot for number triangle C program

7.26.2012

Number pyramid

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;
}


/************Output************/


Output of number pyramid C program
Screen shot for number triangle C program

7.24.2012

Number structure

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;
}


/**************Output**************/


Output of number pyramid C program
Screen shot for number triangle C program

Number pyramid

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;
}


/************Output************/


Output of C program for number pyramid C program
Screen shot for number pyramid C program