Showing posts with label of. Show all posts
Showing posts with label of. Show all posts

Monday, 31 March 2014

C programs | Swapping of two numbers without third(temp) variable in C

C programs | Swapping of two numbers without third(temp) variable in C

Source Code:-)

#include <stdio.h>

int main()
{
   int a, b;

   printf("Enter two integers to swap\n");
   scanf("%d%d", &a, &b);

   a = a + b;
   b = a - b;
   a = a - b;

   printf("a = %d\nb = %d\n",a,b);
   return 0;
}

C Programs | Swapping of two numbers in c

C programs | Swapping of two numbers in c

Source code:-)

#include <stdio.h>

int main()
{
   int x, y, temp;

   printf("Enter the value of x and y\n");
   scanf("%d%d", &x, &y);

   printf("Before Swapping\nx = %d\ny = %d\n",x,y);

   temp = x;
   x    = y;
   y    = temp;

   printf("After Swapping\nx = %d\ny = %d\n",x,y);

   return 0;
}

Output:-)

Enter the value of x and y

3

6

Before swapping 

x=3 

y=6 

After swapping


x=6

y=3

C Program | To Find ASCII Value of a Character-Source code

C Program | To Find ASCII Value of a Character

Source code:-)

 /* Source code to find ASCII value of a character entered by user */

#include <stdio.h>
int main(){
    char c;
    printf("Enter a character: ");
    scanf("%c",&c);        /* Takes a character from user */
    printf("ASCII value of %c = %d",c,c);
    return 0;
}

Output:-)

Enter a character: G
ASCII value of G = 71

C Program-Find Size of int, float, double and char of System-Syntax-Source Code-Output

 C Program-Find Size of int, float, double and char of System

Syntax of size of Operator:-

 temp = sizeof(operand);
/* Here, temp is a variable of type integer,i.e, sizeof() operator
   returns integer value. */

 

Source Code :-)

/* This program computes the size of variable using sizeof operator.*/ 

#include <stdio.h> 

int main()

int a; 

float b; 

double c; 

char d; 

printf("Size of int: %d bytes\n",sizeof(a)); 

printf("Size of float: %d bytes\n",sizeof(b)); 

printf("Size of double: %d bytes\n",sizeof(c)); 

printf("Size of char: %d byte\n",sizeof(d)); 

return 0; 

}

OUTPUT :-)

Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte

Sunday, 30 March 2014

Java Programs - Alphabetical order of the given Name

 Alphabetical order of the given Name


Program Name:-    alpha.java


import java.io.*;
import java.lang.*;
class alpha
{
public static void main(String args[])throws IOException
 {
 String a[]=new String[10];
 String b;
 int n;
 DataInputStream in=new DataInputStream(System.in);
 System.out.print("\nEnter the Number of name  :");
 n=Integer.parseInt(in.readLine());
 for(int i=0;i<n;i++)
  {
  a[i]=in.readLine();
  }
  for(int i=0;i<n;i++)
  {
  for(int j=i+1;j<n;j++)
   {
    if(a[i].compareTo(a[j])<0)
    {
    b=a[i];
    a[i]=a[j];
    a[j]=b;
    }
   }
  }
 System.out.println("\n Alphabetical order of name is:");
 for(int i=0;i<n;i++)
 {
 System.out.println(a[i]);
 }
 }
}