Total Pageviews

Sunday, November 18, 2012

c program to reverse a number

C Program to reverse a number :- This program reverse the number entered by the user and then prints the reversed number on the screen. For example if user enter 123 as input then 321 is printed as output. In our program we use modulus(%) operator to obtain the digits of a number. To invert number look at it and write it from opposite direction or the output of code is a number obtained by writing original number from right to left. To reverse large numbers use long data type or long long data type if your compiler supports it, if you still have large numbers then use strings or other data structure.



C programming code

 
#include <stdio.h>
 
main()
{
   int n, reverse = 0;
 
   printf("Enter a number to reverse\n");
   scanf("%d",&n);
 
   while (n != 0)
   {
      reverse = reverse * 10;
      reverse = reverse + n%10;
      n = n/10;
   }
 
   printf("Reverse of entered number is = %d\n", reverse);
 
   return 0;
}
 
 
Output of program:
reverse number 
 

JavaScript is a Scripting Language

A scripting language is a lightweight programming language.
JavaScript is programming code that can be inserted into HTML pages.
JavaScript inserted into HTML pages, can be executed by all modern web browsers.
JavaScript is easy to learn.

JavaScript: Writing Into HTML Output

Example

document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph</p>"); 

JavaScript: Reacting to Events

Example

<button type="button" onclick="alert('Welcome!')">Click Me!</button>
                             
     IMPORTANT LINKS TO LEARN MORE

      http://www.w3schools.com/js/default.asp
      http://www.tizag.com/javascriptT/