Thursday 10 November 2016

Data Base

Database handlers create database in such a way that only one set of software program provide access of data to all the users.
The main purpose of database is to operate large amount of information by storing, retrieving and managing.
There are many dynamic websites on the world wide web now a days which are handled through databases. For example, a model to checks the availability of rooms in a hotel. It is an example of dynamic website that uses database.
There are many database available like MySQL, Sybase, Oracle, Mango DB, Informix, Postgre, SQL Server etc.
SQL or Structured Query Language is used to perform operation on the data stored in a database. SQL depends on relational algebra and tuple relational calculus.
A cylindrical structure is used to display the image of a database.

SQL Requirements

  • SQL stands for Structured Query Language.
  • It is designed for managing data in a relational database management system (RDBMS).
  • It is pronounced as S-Q-L or sometime See-Qwell.
  • SQL is a database language, it is used for database creation, deletion, fetching rows and modifying rows etc.
  • SQL is based on relational algebra and tuple relational calculus.
All DBMS like MySQL, Oracle, MS Access, Sybase, Informix, Postgres and SQL Server use SQL as standard database language.

SQL

SQL (Structured Query Language) is used to perform operations on the records stored in database such as updating records, deleting records, creating and modifying tables, views etc.

Class Loader

The classloader is a subsystem of JVM that is used to load classes and interfaces.There are many types of classloaders e.g. Bootstrap classloader,Extension classloader,System classloader, Plugin classloader etc.

Class Loader

The classloader is a subsystem of JVM that is used to load classes and interfaces.There are many types of classloaders e.g. Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc.

JIT

Just-In-Time(JIT) compiler:It is used to improve the performance. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation.Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.

C Program to demonstrate structure

  1. #include <stdio.h>  
  2. #include <string.h>  
  3. struct employee    
  4. {   int id;    
  5.     char name[50];    
  6. }e1;  //declaring e1 variable for structure  
  7. int main( )  
  8. {  
  9.    //store first employee information  
  10.    e1.id=101;  
  11.    strcpy(e1.name, "Soniya");//copying string into char array  
  12.    //printing first employee information  
  13.    printf( "employee 1 id : %d\n", e1.id);  
  14.    printf( "employee 1 name : %s\n", e1.name);  
  15.    return 0;  
  16. }  
Output:
employee 1 id : 101
employee 1 name : Soniya

Types of SEO

White Hat SEO

It refers to the SEO techniques which are in accordance with the SEO guidelines set by the search engines. It means it uses approved search engine optimization techniques to improve the ranking of a site on search engine results pages (SERP).

Unlike Black Hat SEO, it mainly focuses on the human audience opposed to a search engine. People who are looking for a long-term investment on their websites rely on white hat SEO techniques.

Black Hat SEO


It refers to the SEO techniques which are not in accordance with the SEO guidelines set by the search engines. These techniques exploit the weaknesses in search engines to get higher rankings for websites on the search engine results pages (SERP).

It mainly focuses on search engines and not on the human audience. People who are looking for a quick financial return on their website rather than a long term investment use black hat SEO techniques.

Multilevel Dropdown Menu with Pure CSS

<html>
<head>
<title>Multilevel Dropdown Menu with Pure CSS</title>
<style>
.parent {display: block;position: relative;float: left;line-height: 30px;background-color: #4FA0D8;border-right:#CCC 1px solid;}
.parent a{margin: 10px;color: #FFFFFF;text-decoration: none;}
.parent:hover > ul {display:block;position:absolute;}
.child {display: none;}
.child li {background-color: #E4EFF7;line-height: 30px;border-bottom:#CCC 1px solid;border-right:#CCC 1px solid; width:100%;}
.child li a{color: #000000;}
ul{list-style: none;margin: 0;padding: 0px; min-width:10em;}
ul ul ul{left: 100%;top: 0;margin-left:1px;}
li:hover {background-color: #95B4CA;}
.parent li:hover {background-color: #F0F0F0;}
.expand{font-size:12px;float:right;margin-right:5px;}
</style>
</head>
<body>
<ul id="menu">
<li class="parent"><a href="#">Popular Toys</a>
<ul class="child">
<li class="parent"><a href="#">Video Games <span class="expand">&raquo;</span></a>
<ul class="child">
<li><a href="#">Car</a></li>
<li><a href="#">Bike Race</a></li>
<li><a href="#">Fishing</a></li>
</ul>
</li>
<li><a href="#">Barbies</a></li>
<li><a href="#">Teddy Bear</a></li>
<li><a href="#">Golf Set</a></li>
</ul>
</li>
<li class="parent"><a href="#">Recent Toys</a>
<ul class="child">
<li><a href="#">Yoyo</a></li>
<li><a href="#">Doctor Kit</a></li>
<li class="parent"><a href="#">Fun Puzzle<span class="expand">&raquo;</span></a>
<ul class="child">
<li><a href="#" nowrap>Cards</a></li>
<li><a href="#" nowrap>Numbers</a></li>
</ul>
</li>
<li><a href="#">Uno Cards</a></li>
</ul>
</li>
<li class="parent"><a href="#">Toys Category</a>
<ul class="child">
<li><a href="#">Battery Toys</a></li>
<li class="parent"><a href="#">Remote Toys <span class="expand">&raquo;</span></a>
<ul class="child">
<li><a href="#">Cars</a></li>
<li><a href="#">Aeroplane</a></li>
<li><a href="#">Helicopter</a></li>
</ul>
</li>
<li><a href="#">Soft Toys</a>
</li>
<li><a href="#">Magnet Toys</a></li>
</ul>
</li>
</ul>
</body>
</html>

jquery colour picker

<html>
<body>
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<style type="text/css">
#pointer {
position: absolute;
top: 0;
left: 0;
height: 20px;
width: 20px;
border:#000 1px solid;
border-radius:50%;
}
.circular-div{padding:20px;width:25px;height:200px;float:left;margin:1px;}
#aqua{background:aqua;}
#yellow{background:yellow;}
#bisque{background:bisque;}
#aquamarine{background:aquamarine;}
#target{float:left;padding:20px;height:200px;width:250px;border:#F0F0F0 1px solid;}
</style>
<div id="demo-content">
<div class="circular-div" id="aquamarine" onClick="pickColor(this.id);">

</div>
<div class="circular-div"  id="bisque" onClick="pickColor(this.id);">

</div>
<div class="circular-div"  id="yellow" onClick="pickColor(this.id);">
</div>
<div class="circular-div"  id="aqua" onClick="pickColor(this.id);">
</div>
<div id="target" onClick="applyColor();">Click to Apply Color</div>
<div id="pointer"></div>
</div>
<script type="text/javascript">
var demoContent = document.getElementById("demo-content");
demoContent.addEventListener('mousemove',function(event) {
$("#pointer").css({'top':event.pageY+'px','left':event.pageX+'px'});
});
function applyColor(){
$("#target").css('background-color',$("#pointer").css('background-color'));
}
function pickColor(id){
$("#pointer").css('background-color',id);
}
</script>
</body>
</html>

File size validation using jquery

<html>
<head>
<style>
body{width:610;}
#frmFile {border-top:#F0F0F0 2px solid;background:#FAF8F8;padding:10px;}
.demoInputBox{padding:10px; border:#F0F0F0 1px solid; border-radius:4px;background-color:#FFF;}
#file_error{color: #FF0000;}
#btnSubmit{background-color:#2FC332;border:0;padding:10px 40px; margin:15px 0px; color:#FFF;border:#F0F0F0 1px solid; border-radius:4px;}
</style>
<script src="http://code.jquery.com/jquery-2.1.1.js"></script>
<script>
function validate() {
$("#file_error").html("");
$(".demoInputBox").css("border-color","#F0F0F0");
var file_size = $('#file')[0].files[0].size;
if(file_size>2097152) {
$("#file_error").html("File size is greater than 2MB");
$(".demoInputBox").css("border-color","#FF0000");
return false;
}
return true;
}
</script>
</head>
<body>
<form name="frmFile" id="frmFile" method="post" action=""  onSubmit="return validate();">
<div><input type="file" name="file" id="file" class="demoInputBox" /> <span id="file_error"></span></div>
<div><input type="submit" id="btnSubmit" value="Upload"/></div>
</form>
</body>
</html>

jQuery Accordion

<html>
    <head>
      <title>jQuery Accordion</title>
<style>
.question{font-size:0.9em;padding:10px;margin:1px;background-color:#B24926;cursor:pointer;}
.answer{display:none;padding:10px;margin:1px;background-color:#CCC;}
</style>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.2/jquery-ui.js"></script>
<script>
$(function() {
$( "#accordion" ).accordion();
});
</script>
    </head>
    <body>
    <div id="accordion">
   <div class="question">What is PHP?</div>
   <div class="answer">A server side scripting language.</div>

   <div class="question">What is php.ini?</div>
   <div class="answer">php.ini is the configuration file which contains many directives and flags.</div>

   <div class="question">How to set PHP configuration?</div>
   <div class="answer">By using php.ini configuration file.</div>
    </div>
    </body>
</html>

Favourite star rating using jquery

<style>
li{display: inline-block;color: #F0F0F0;text-shadow: 0 0 1px #666666;font-size:30px;}
.highlight, .selected {color:#F4B30A;text-shadow: 0 0 1px #F48F0A;}
</style>
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
function highlightStar(obj) {
removeHighlight();
$('li').each(function(index) {
$(this).addClass('highlight');
if(index == $("li").index(obj)) {
return false;
}
});
}

function removeHighlight() {
$('li').removeClass('selected');
$('li').removeClass('highlight');
}

function addRating(obj) {
$('li').each(function(index) {
$(this).addClass('selected');
$('#rating').val((index+1));
if(index == $("li").index(obj)) {
return false;
}
});
}

function resetRating() {
if($("#rating").val()) {
$('li').each(function(index) {
$(this).addClass('selected');
if((index+1) == $("#rating").val()) {
return false;
}
});
}
}
</script>
<input type="hidden" name="rating" id="rating" />
<ul onMouseOut="resetRating();">
  <li onmouseover="highlightStar(this);" onmouseout="removeHighlight();" onClick="addRating(this);">&#9733;</li>
  <li onmouseover="highlightStar(this);" onmouseout="removeHighlight();" onClick="addRating(this);">&#9733;</li>
  <li onmouseover="highlightStar(this);" onmouseout="removeHighlight();" onClick="addRating(this);">&#9733;</li>
  <li onmouseover="highlightStar(this);" onmouseout="removeHighlight();" onClick="addRating(this);">&#9733;</li>
  <li onmouseover="highlightStar(this);" onmouseout="removeHighlight();" onClick="addRating(this);">&#9733;</li>
</ul>

Check-Uncheck all Checkbox Using jquery

<style>
body{width:610px;}
#frmCheclAll {border-top:#F0F0F0 2px solid;background:#FAF8F8;padding:10px;}
#divCheckAll{background-color:#F2F2F2;border:#DADADA 1px solid;margin-bottom:15px;width:6em;padding:4px 10px;}
#divCheckboxList{border-top:#DADADA 1px solid;}
.divCheckboxItem{padding:6px 10px;}

</style>
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script>
function check_uncheck_checkbox(isChecked) {
if(isChecked) {
$('input[name="language"]').each(function() {
this.checked = true;
});
} else {
$('input[name="language"]').each(function() {
this.checked = false;
});
}
}
</script>
<div id="frmCheclAll">
<div id="divCheckAll">
<input type="checkbox" name="checkall" id="checkall" onClick="check_uncheck_checkbox(this.checked);" />Check All</div>
<div id="divCheckboxList">
<div class="divCheckboxItem"><input type="checkbox" name="language" id="language1" value="English" />English</div>
<div class="divCheckboxItem"><input type="checkbox" name="language" id="language2" value="French" />French</div>
<div class="divCheckboxItem"><input type="checkbox" name="language" id="language3" value="German" />German</div>
<div class="divCheckboxItem"><input type="checkbox" name="language" id="language4" value="Latin" />Latin</div>
</div>
</div>

DropDown with Search using jQuery

<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.1/js/select2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var country = ["Australia", "Bangladesh", "Denmark", "Hong Kong", "Indonesia", "Netherlands", "New Zealand", "South Africa"];
$("#country").select2({
 data: country
});
});
</script>
</head>
<body>
<h1>DropDown with Search using jQuery</h1>
<div>
<select id="country" style="width:300px;">
<!-- Dropdown List Option -->
</select>
</div>
</body>
</html>

Enable Disable Submit Button Based on Validation

<html>
<head>
<title>Enable Disable Submit Button Based on Validation</title>
<style>
#btn-submit{padding: 10px 20px;background: #555;border: 0;color: #FFF;display:inline-block;margin-top:20px;cursor: pointer;}
#btn-submit:disabled{padding: 10px 20px;background: #CCC;border: 0;color: #FFF;display:inline-block;margin-top:20px;cursor: no-drop;}
.validation-error {color:#FF0000;}
.input-control{padding:10px;}
.input-group{margin-top:10px;}
</style>
</head>
<body>
<h1>Enable Disable Submit Button Based on Validation</h1>
<form id="frm" method="post">
   <div class="input-group">Name <span class="name-validation validation-error"></span></div>
   <div>
        <input type="text" name="name" id="name" class="input-control" onblur="validate()" />
   </div>
   
   <div class="input-group">Email <span class="email-validation validation-error"></span></div>
   <div>
<input type="text" name="email" id="email" class="input-control" onblur="validate()" />
   </div>

   <div>
        <button type="submit" name="btn-submit" id="btn-submit" disabled="disabled">Submit</button>
    </div>
</form>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script>
function validate() {

var valid = true;
valid = checkEmpty($("#name"));
valid = valid && checkEmail($("#email"));

    $("#btn-submit").attr("disabled",true);
if(valid) {
$("#btn-submit").attr("disabled",false);
}
}
function checkEmpty(obj) {
var name = $(obj).attr("name");
$("."+name+"-validation").html("");
$(obj).css("border","");
if($(obj).val() == "") {
$(obj).css("border","#FF0000 1px solid");
$("."+name+"-validation").html("Required");
return false;
}

return true;
}
function checkEmail(obj) {
var result = true;

var name = $(obj).attr("name");
$("."+name+"-validation").html("");
$(obj).css("border","");

result = checkEmpty(obj);

if(!result) {
$(obj).css("border","#FF0000 1px solid");
$("."+name+"-validation").html("Required");
return false;
}

var email_regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,3})+$/;
result = email_regex.test($(obj).val());

if(!result) {
$(obj).css("border","#FF0000 1px solid");
$("."+name+"-validation").html("Invalid");
return false;
}

return result;
}
</script>
</body>
</html>

Formatting Date With jQuery Date Picker

<html>
<head>
  <title>Formatting Date With jQuery Date Picker</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
  <script src="http://code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  <style>
body{width:610px;}

#frm-date-format {
padding: 20px 40px;
background: #82ade4;
color: #FFF;
font-size: 1.2em;
}

.frm-input-row {
margin-bottom: 20px;
}

.frm-input {
padding: 10px;
width: 250px;
font-size: 0.8em;
}
  </style>
  <script>
$("#restricting").datepicker({
    yearRange: "-20:+0", // this is the option you're looking for
    showOn: "both",
    buttonImage: "templates/images/calendar.gif",
    buttonImageOnly: true
});
  </script>
</head>
<body>
<div id="frm-date-format">
<div class="frm-input-row">
<div class="frm-label">Select Date:</div>
<div><input type="text" id="datepicker" size="30" class="frm-input"></div>
</div>
<div class="frm-input-row">
<div>Formats:</div>
<div>
<select id="date-format" onchange="setDateFormat(this.value);" class="frm-input">
<option value="mm/dd/yy">mm/dd/yy</option>
<option value="dd/mm/yy">dd/mm/yy</option>
<option value="yy-mm-dd">yy-mm-dd</option>
<option value="M d, y">M d, y</option>
</select>
</div>
</div>
</div>
</body>
</html>

Jquery Password Strength Checker

<html>
<body>
<style>
body{width:610px;}
#frmCheckPassword {border-top:#F0F0F0 2px solid;background:#FAF8F8;padding:10px;}
.demoInputBox{padding:7px; border:#F0F0F0 1px solid; border-radius:4px;}
#password-strength-status {padding: 5px 10px;color: #FFFFFF; border-radius:4px;margin-top:5px;}
.medium-password{background-color: #E4DB11;border:#BBB418 1px solid;}
.weak-password{background-color: #FF6600;border:#AA4502 1px solid;}
.strong-password{background-color: #12CC1A;border:#0FA015 1px solid;}
</style>
<script src="https://code.jquery.com/jquery-2.1.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
function checkPasswordStrength() {
var number = /([0-9])/;
var alphabets = /([a-zA-Z])/;
var special_characters = /([~,!,@,#,$,%,^,&,*,-,_,+,=,?,>,<])/;

if($('#password').val().length<6) {
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('weak-password');
$('#password-strength-status').html("Weak (should be atleast 6 characters.)");
} else {  
   if($('#password').val().match(number) && $('#password').val().match(alphabets) && $('#password').val().match(special_characters)) {          
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('strong-password');
$('#password-strength-status').html("Strong");
        } else {
$('#password-strength-status').removeClass();
$('#password-strength-status').addClass('medium-password');
$('#password-strength-status').html("Medium (should include alphabets, numbers and special characters.)");
        }
}
}
</script>

<div name="frmCheckPassword" id="frmCheckPassword">
<label>Password:</label>
<input type="password" name="password" id="password" class="demoInputBox" onKeyUp="checkPasswordStrength();" /><div id="password-strength-status"></div>
</div>
</body>
</html>

Clone HTML using jQuery

<HTML>
<HEAD>
<TITLE>Clone HTML using jQuery</TITLE>
<style>
.float-clear{clear:both;}
.float-left{float:left;}
#demo-outer {background-color: #F0F0F0;}
.product-item input[type="text"] {padding: 5px;border:#ccc 1px solid;margin: 0px 10px;}
.product-item input[type="checkbox"] {margin: 10px;}
#product-header div{padding: 20px 5px 15px;margin: 0px 10px;}
.col-heading{width:150px;font-size:16px;font-weight:bold;}
.btn-action{padding:10px;}
.btn-action input[type="button"]{padding:5px; border:#CCCCCC 1px solid;}
</style>
<SCRIPT src="http://code.jquery.com/jquery-2.1.1.js"></SCRIPT>
<SCRIPT>
function addMore() {
$(".product-item:last").clone().insertAfter(".product-item:last");
}
function deleteRow() {
$('DIV.product-item').each(function(index, item){
jQuery(':checkbox', this).each(function () {
            if ($(this).is(':checked')) {
$(item).remove();
            }
        });
});
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name="frmProduct" method="post" action="">
<DIV id="demo-outer">
<DIV id="product-header">
<DIV class="float-left">&nbsp;</DIV>
<DIV class="float-left col-heading">Grade</DIV>
<DIV class="float-left col-heading">Credits</DIV>
</DIV>
<DIV id="product">
<DIV class="product-item float-clear" style="clear:bo;">
<DIV class="float-left"><input type="checkbox" name="item_index[]" /></DIV>
<DIV class="float-left"><input type="text" name="item_name[]" /></DIV>
<DIV class="float-left"><input type="text" name="item_price[]" /></DIV>
</DIV>
</DIV>
<DIV class="btn-action float-clear">
<input type="button" name="add_item" value="Add More" onClick="addMore();" />
<input type="button" name="del_item" value="Delete" onClick="deleteRow();" />
</DIV>
</DIV>
</form>
</BODY>
</HTML>

JavaScript validation with image

<html>
<body>
<script type="text/javascript">
function validate(){
var name=document.f1.name.value;
var passwordlength=document.f1.password.value.length;
var status=false;
if(name==""){
document.getElementById("namelocation").innerHTML=
" <img src=''/> Please enter your name";
status=false;
}else{
document.getElementById("namelocation").innerHTML=" <img src=''/>";
status=true;
}
 
if(passwordlength<6){
document.getElementById("passwordlocation").innerHTML=
" <img src=''/> Password must be greater than 6";
status=false;
}else{
document.getElementById("passwordlocation").innerHTML=" <img src=''/>";
}
 
return status;
}
</script>
<form name="f1" action="" onsubmit="return validate()">
<table>
<tr><td>Name:</td><td><input type="text" name="name"/>
<span id="namelocation" style="color:red"></span></td></tr>
<tr><td>Password:</td><td><input type="password" name="password"/>
<span id="passwordlocation" style="color:red"></span></td></tr>
<tr><td colspan="2"><input type="submit" value="register"/>  </td></tr>
</table>
</form>
</body>
</html>

JavaScript Retype Password Validation

<!DOCTYPE html>
<html>
<head>
<script type="text/">
function matchpass(){
var firstpassword=document.f1.password.value;
var secondpassword=document.f1.password2.value;

if(firstpassword==secondpassword){
return true;
}
else{
alert("password must be same!");
return false;
}
}
</script>
</head>
<body>

<form name="f1" action="" onsubmit="return matchpass()">
Password:<input type="password" name="password" /><br/>
Re-enter Password:<input type="password" name="password2"/><br/>
<input type="submit">
</form>

</body>
</html>

Javascript Form Validation Example

<html>
<body>
<script>
function validateform(){
var name=document.myform.name.value;
var password=document.myform.password.value;
 
if (name==null || name==""){
  alert("Name can't be blank");
  return false;
}else if(password.length<6){
  alert("Password must be at least 6 characters long.");
  return false;
  }
}
</script>
<body>
<form name="myform" method="post" action="" onsubmit="return validateform()" >
Name: <input type="text" name="name"><br/>
Password: <input type="password" name="password"><br/>
<input type="submit" value="register">
</form>
</body>
</html>

C Program to reverse a String

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. void main(){  
  4.   char str[20];  
  5.   clrscr();  
  6.   printf("Enter string: ");  
  7.   gets(str);//reads string from console  
  8.   printf("String is: %s",str);  
  9.   printf("\nReverse String is: %s",strrev(str));  
  10.   getch();  
  11. }    
Output:
Enter string: welcome
String is: welcome
Reverse String emoclew

Type Casting in C

Type casting allows us to convert one data type into other. In C language, we use cast operator for type casting which is denoted by (type).
Syntax:
  1. (type)value;   

Dynamic memory allocation in C

The concept of dynamic memory allocation in c language enables the C programmer to allocate memory at runtime. Dynamic memory allocation in c language is possible by 4 functions of stdlib.h header file.
  1. malloc()
  2. calloc()
  3. realloc()
  4. free()
Before learning above functions, let's understand the difference between static memory allocation and dynamic memory allocation.
static memory allocationdynamic memory allocation
memory is allocated at compile time.memory is allocated at run time.
memory can't be increased while executing program.memory can be increased while executing program.
used in array.used in linked list.
Now let's have a quick look at the methods used for dynamic memory allocation.
malloc()allocates single block of requested memory.
calloc()allocates multiple block of requested memory.
realloc()reallocates the memory occupied by malloc() or calloc() functions.
free()frees the dynamically allocated memory.

C Program to print the Palindrome of an number

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. main()  
  4. {  
  5. int n,r,sum=0,temp;  
  6. clrscr();  
  7. printf("enter the number=");  
  8. scanf("%d",&n);  
  9. temp=n;  
  10. while(n>0)  
  11. {  
  12. r=n%10;  
  13. sum=(sum*10)+r;  
  14. n=n/10;  
  15. }  
  16. if(temp==sum)  
  17. printf("palindrome number ");  
  18. else  
  19. printf("not palindrome");  
  20. getch();  
  21. }  
Output:
enter the number=151
palindrome  number
enter the number=5621
not palindrome  number

Wednesday 9 November 2016

C Program to Find the armstrong of a number

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. main()  
  4. {  
  5. int n,r,sum=0,temp;  
  6. clrscr();  
  7. printf("enter the number=");  
  8. scanf("%d",&n);  
  9. temp=n;  
  10. while(n>0)  
  11. {  
  12. r=n%10;  
  13. sum=sum+(r*r*r);  
  14. n=n/10;  
  15. }  
  16. if(temp==sum)  
  17. printf("armstrong  number ");  
  18. else  
  19. printf("not armstrong number");  
  20. getch();  
  21. }  
Output:
enter the number=153
armstrong number
enter the number=5
not armstrong number

C Program to Reverse a Number

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. main()  
  4. {  
  5. int n, reverse=0, rem;  
  6. clrscr();  
  7. printf("Enter a number: ");  
  8.   scanf("%d", &n);  
  9.   while(n!=0)  
  10.   {  
  11.      rem=n%10;  
  12.      reverse=reverse*10+rem;  
  13.      n/=10;  
  14.   }  
  15.   printf("Reversed Number: %d",reverse);  
  16. getch();  
  17. }  
Output:
Enter a number: 123
Reversed Number: 321

C Program for Swapping two Numbers

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. main()  
  4. {  
  5. int a=10, b=20;    
  6. clrscr();    
  7. printf("Before swap a=%d b=%d",a,b);    
  8.   
  9. a=a+b;//a=30 (10+20)  
  10. b=a-b;//b=10 (30-20)  
  11. a=a-b;//a=20 (30-10)  
  12.   
  13. printf("\nAfter swap a=%d b=%d",a,b);  
  14. getch();  
  15. }  
Output:
Before swap a=10 b=20
After swap a=20 b=10