Posts

Java program to check whether a given number is palindrome or not

import java.util.*; class palindrome  {   public static void main(String s[] ){   try{   Scanner sc =new Scanner(System.in);   System.out.println("Enter number");   int num= sc.nextInt();   int n = num;   int rev=0;   System.out.println("Number: ");   System.out.println(" "+ num);   while(num>0){   int r=num%10;   num=num/10;   rev=rev*10+r;     }   System.out.println("After reversing the number: "+ " ");   System.out.println(" "+ rev);    if(n == rev){   System.out.print("Number is palindrome!");   }   else{   System.out.println("Number is not palindrome!");   }   }   catch(Exception e){   System.out.println("Out of range!");   }   } }

C Code Snippet to Print Swastik Symbol

Print Swastik symbol in C

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