Posts

Showing posts from 2011

Largest No. Out Of Two Nos. Without Using Relational Operator or >,<,+,- In C Language

# include <stdio.h> void main() { int a,b,c; clrscr(); printf(" \n Enter First No.:- "); scanf("%d",&a); printf(" \n Enter Second No.:- "); scanf("%d",&b); c = a/b; if(c==0)     printf(" \n %d is greater. ",b); else     printf(" \n %d is greater. ",a); getch(); }

To Find Out Largest No. Out Of 3 Nos. Without Using If In C Language

# include <stdio.h> void main() { int a,b,c,m; clrscr(); printf(" \n\n\n  Program To Find Out Largest No. Out Of 3 Nos. Without Using If In C Language "); printf(" \n\n\n\t Please Enter The 1st No. : "); scanf(" %d ",&a); printf(" \n\t Please Enter The 2nd No. : "); scanf(" %d ",&b); printf(" \n\t Please Enter The 3rd No. : "); scanf(" %d ",&c); m = a>b?(a>c?a:c):(b>c?b:c); printf(" \n\n\n\t\t The Largest No. Is %d ",m); getch(); }

Read a string and check whether it is palindrome or not.

 //Read a string and print the string is palindrome or NOT palindrome. # include <stdio.h> void main() { char a[500],b[500]; clrscr(); printf(" \n Enter A String :-  "); scanf(" %s ",&a); strcpy(b,a); //copies string a to b strrev(b);  //reverses string b if(strcmp(a,b)==0)  //compares if the original and reverse strings are same printf(" \n %s is a palindrome ",a); else printf(" \n %s is not a palindrome ",a); getch(); } //Read a string and print the string is palindrome or NOT palindrome without using inbuilt functions. # include <stdio.h> void main() { char a[500]; int i,b; clrscr(); printf(" \n Enter A String :-  "); scanf(" %s ",&a); b = strlen(a); for (i=0;i<=((b-1)/2);i++) {     if(a[i] != a[b-1-i])     printf(" \n %s is not palindrome ",a); } printf(" \n %s is palindrome ",a); getch(); }

To Find First,Second &Third Largest No. From A Given Array

# include <iostream.h> # include <conio.h> void main() { clrscr(); int f,s,t,a[50],n,i; cout<<" \n Enter Size Of Array: "; cin>>n; cout<<" \n Enter The Array:- "; for (i=0;i<n;i++) {     cin>>a[i]; } f = a[0]; s = a[0]; t = a[0]; for (i=0;i<n-1;i++) {     if (a[i] > f)      f = a[i+1];     } for(i=0;i<n-1;i++) {      if ((a[i] > s) && (f > a[i]) )         s = a[i+1]; }       for (i=0;i<n-1;i++) {      if ((a[i] > t) && (f > a[i]) && (s > a[i]))         t = a[i+1]; } cout<<" \n The First Largest No. Is " <<f; cout<<" \n The Second Largest No. Is "<<s; cout<<" \n The Third Largest No Is. "<<t; getch(); }

To Find Modulus Of Two No. Without Using Modulus Operator

# include <stdio.h> void main() { int n1,n2,res,result; clrscr(); printf(" \n Enter First No . "); scanf(" %d ",&n1); printf(" \n Enter Second No. "); scanf(" %d ",&n2); res = n1/n2; result = n1-(n2*res); printf(" \n The Modulus Of %d and %d is %d . ",n1,n2,result); getch(); }

Matrix Addition In C Language

#include <stdio.h> int main(){   int a[3][3],b[3][3],c[3][3],i,j;   printf( "Enter the First matrix->" );   for (i=0;i<3;i++)       for (j=0;j<3;j++)            scanf( "%d" ,&a[i][j]);   printf( "\nEnter the Second matrix->" );   for (i=0;i<3;i++)       for (j=0;j<3;j++)            scanf( "%d" ,&b[i][j]);   printf( "\nThe First matrix is\n" );   for (i=0;i<3;i++){       printf( "\n" );       for (j=0;j<3;j++)            printf( "%d\t" ,a[i][j]);   }   printf( "\nThe Second matrix is\n" );   for (i=0;i<3;i++){       printf( "\n" );       for (j=0;j<3;j++)       printf( "%d\t" ,b[i][j]); ...

INSERT AN ELMENT IN AN ARRAY AT DESIRED POSITION USING C PROGRAM

#include <stdio.h> int main (){ int a[50],size,num,i,pos,temp; printf( "\nEnter size of the array: " ); scanf( "%d" ,&size); printf( "\nEnter %d elements in to the array: " ,size); for (i=0;iscanf( "%d" ,&a[i]); printf( "\nEnter position and number to insert: " ); scanf( "%d %d" ,&pos,&num); i=0; while (i!=pos-1) i++; temp=size++; while (i{ a[temp]=a[temp-1]; temp--; } a[i]=num; for (i=0;iprintf( " %d" ,a[i]); return 0; }

DELETE ELEMENT FROM AN ARRAY AT DESIRED POSITION USING C

#include <stdio.h> void main () {   int a[50],i,pos,size;   clrscr();   printf( "\nEnter size of the array: " );   scanf( "%d" ,&size);   printf( "\nEnter %d elements in to the array: " ,size);   for (i=0;i<size;i++)             scanf( "%d" ,&a[i]);   printf( "\nEnter position where to delete: " );   scanf( "%d" ,&pos);   i=0;   while (i!=pos-1)             i++;   while (i<size)   {             a[i]=a[i+1];             i++;   }   size--;   for (i=0;i<size;i++)             printf( " %d" ,a[i]);   getch(); }

FIND OUT LARGEST NUMBER IN AN ARRAY USING C PROGRAM

#include <stdio.h> int main (){   int a[50],size,i,big;   printf( "\nEnter the size of the array: " );   scanf( "%d" ,&size);   printf( "\nEnter %d elements in to the array: ”, size);   for (i=0;i<size;i++)       scanf( "%d" ,&a[i]);   big=a[0];   for (i=1;i<size;i++){       if (big<a[i])            big=a[i];   }   printf( "\nBiggest: %d" ,big);   return 0; }

C Program to Get the Current System Date

#include <dos.h> #include <stdio.h> int main(void) { struct date d; getdate(&d); printf(“The current year is: %d\n”, d.da_year); printf(“The current day is: %d\n”, d.da_day); printf(“The current month is: %d\n”, d.da_mon); return 0; }

C Program to Get the Current System Time

#include <stdio.h> #include <dos.h> int main(void) { struct time t; gettime(&t); printf(“The current time is: %2d:%02d:%02d\n”, t.ti_hour, t.ti_min, t.ti_sec); return 0; }

Java program to display Local machines IP Address

import java.net.*; import java.io.*; public class iplocalmac {     public static void main(String args[]) throws Exception     {         InetAddress ipadd =InetAddress.getLocalHost();         System.out.println("Host and Address :"+ipadd);         System.out.println("Host name :"+ipadd.getHostName());         String n=ipadd.toString();         System.out.println("IP address :"+n.substring(n.indexOf("/")+1));     } }

Java program to display the IP Address of a particular Host

import java.net.*; import java.io.*; public class iphost {     public static void main(String args[]) throws Exception     {         System.out.println("Enter the host name :");         String n=new DataInputStream(System.in).readLine();         InetAddress ipadd =InetAddress.getByName(n);         System.out.println("IP address :"+ipadd);     } }