Posts

Showing posts from February, 2019

Factor of a number

C Program to find the factor of a number   #include<stdio.h> int main() {     int  n, i;     printf("\nEnter the number to find the factors of :  ");     scanf("%d",&n);     printf("\n\n\nFactors of %d are: \n", n);     for(i = 1; i <= n/2; i++)     {         if(n%i == 0)             printf("\t\t%d\n", i);     }     return 0; } output: Enter the number to find the factors of :  128 Factors of 128 are:                 1                 2                 4                 8                 16                 32                 64

Palindrome Number

Java Program whether the number is Palindrome or not. Implementation :- import java.util.Scanner; class Palindm {     public static void main(String[] args)     {         int rm, rv=0,act;         System.out.println("Enter a number: ");         Scanner s = new Scanner(System.in);         int num = s.nextInt();         act=num;         while(num > 0)         {             rm = num%10;             rv = rv*10 + rm;             num = num/10;         }         if(rv==act)         {             System.out.println(act+" is a Palindrome Number.");         }         else             System.out.println(act+" is not a Palindrome Number.");     } } D:\AllPrograms\1232>javac Palindm.java D:\AllPrograms\1232>java Palindm Enter a number: 121 121 is a Palindrome Number. D:\AllPrograms\1232>java Palindm Enter a number: 432 432 is not a Palindrome Number. D:\AllPrograms\1232>java Palindm Enter a number: 65656 65656 is a Palindrome Number.

Java Program to Check Prime or Not

To check the entered number by user is prime or not have to know about the prime number. Prime Number :- Prime Number is divisible by 1 or itself. So in below program we check from 2 to the half of the number  and divide it with integer i every iteration and count it division by counter c. If counter is c is then it is prime number otherwise number is not Prime. Implementation :- import java.util.Scanner; class PrimeNum {     public static void main(String[] args)     {         System.out.println("Enter a number: ");         Scanner sc = new Scanner(System.in);         int num = sc.nextInt();         int c=0,i;         for(i=2; i<=num/2; i++)         {             if(num%i==0)             {                 c++;                 break;             }                }         if(c==0)            {                System.out.println(num+" is a prime number");            }         else         {              System.out.println(num+" is not a prime number&

Table of number

Java Program For table of a number entered by User Implementation :- import java.util.Scanner; public class Table {     public static void main(String[] args)     {         System.out.println("Enter a number: ");         Scanner sc = new Scanner(System.in);         int num = sc.nextInt();         for(int i=1; i<=10; i++)            {                System.out.println(num+" x "+i+ " = "+i*num);            }     } }  Output:     D:\AllPrograms\1232>javac Table.java D:\AllPrograms\1232>java Table Enter a number: 34 34 x 1 = 34 34 x 2 = 68 34 x 3 = 102 34 x 4 = 136 34 x 5 = 170 34 x 6 = 204 34 x 7 = 238 34 x 8 = 272 34 x 9 = 306 34 x 10 = 340  

To check the given charecter is vowel or Consonant

Java Program To check the given charecter is vowel or Consonant  Implementation :- import java.util.Scanner; class VowelConst1 {     public static void main(String[] args)     {         System.out.println("Enter a Character: ");         Scanner sc = new Scanner(System.in);         char ch = sc.next().charAt(0);         if(ch =='a' || ch =='A'|| ch=='e' || ch =='E' || ch =='i' || ch =='I' || ch =='o' || ch =='O' || ch =='u' || ch =='U')             {                 System.out.println("Character is Vowel");             }         else            {                System.out.println("Character is consonant");            }     } }  Output:  Enter a Character:  a  Character is Vowel

Factorial of a number entered by User

Factorial :- The factorial (represent with symbol: ! ) multiply all whole numbers from our chosen number down to 1. The general formula of factorial can be written in fully expanded form as :- n! = n x (n-1) x (n-2) x ...x 3 x 2 x 1. or in partially expanded form as n! = n  x (n-1)!. Examples :- 1! = 1 3! = 3 x 2 x 1 = 6 4! = 4 × 3 × 2 × 1 = 24 7! = 7 × 6 × 5 × 4 × 3 × 2 × 1 = 5040 0! = 1 n! = n x (n-1)! 1! = 1 x (1-1)! 1! = 1 x (0)! 0!=must be equal to 1 then only it give the result as 1. 1! = 1 Implimentatin of factorial program:- n =int(input("Enter the number to find factorial: ")) fact=1 if(n<0):     print("Factorial is not possible for negative number! ") elif(n==0 or n==1):     print("The factorial of ",n," is ",fact) else:     for i in range(1,n + 1):         fact = fact*i     print("The factorial of ",n," is ",fact)

Find large between two number

Factorial Program Find  large  between two number enter by User  Input Format: The first line of input contains two numbers separated by a space Output Format: Print the larger number x, y = tuple(list(map(int, input("Enter the two number to find the largest. ").split(' ')))) print(max(x,y))                       OR x,y = input("Enter the two number to find the largest. ").split(" ") x = int(x) y = int(y) if(x>y):     print(x) else:     print(y)

Loops, List and Sum program in Python

Here is the program for loops, list and sum in python Question: The first line of the input contains a number N representing the number of elements in array A. The second line of the input contains N numbers separated by a space. (after the last elements, there is no space) Output Format: Print the resultant array elements separated by a space. (no space after the last element) Implimentation-: n=int(input()) arr=list(map(int,input().split(" "))) for i in range(n):   print(arr[i]+arr[-i-1], end = " ") OR N = int(input()) A = [int(i) for i in input().split(" ")] B = [] for i in range(len(A)-1, -1,-1):     B.append(A[i]) C = [] for i in range(len(B)):     C.append(A[i]+B[i]) for i in range(len(C)):     if(i==len(C)-1):         print(C[i])     else:         print(C[i],end=" ")

HTML code for Resume

CODE <!DOCTYPE html> <html>   <head>     <title>Sample page</title>   </head>   <body bgcolor="lightblue">         <h1 align="center"> !!! Resume !!!</h1><hr>     <div>     <h1>Personal Detail</h1><hr>     <img src="Image\IMG1.jpg" align="right" height="120px" width="100px">     <font size="4" style="font-family: verdana">     <table width="40%">         <tr>             <td><b>Name:</b></td>             <td>Pankaj</td>         </tr>         <tr>             <td><b>Address:</b></td>             <td><p>Gandhi Hostel, REC Ambedkar Nagar</p></td>         </tr>         <tr>             <td><b>Mobile Number:</b></td>             <td>+

C program for DFA accept binary string which decimal equivalent is divisible by 5

Image
DFA accept binary string which decimal equivalent is divisible by 5     Binary string decimal equivalent(a) We need that the number of a's will be only multiple of 5, mod(5)=0 e.g 0mod(5)=0,5mod(5)=0,10mod(5)=0 #include <stdio.h> #define TOTAL_STATES 5 #define FINAL_STATES 1 #define ALPHABET_CHARCTERS 2 #define UNKNOWN_SYMBOL_ERR 0 #define NOT_REACHED_FINAL_STATE 1 #define REACHED_FINAL_STATE 2 enum DFA_STATES{q0,q1,q2,q3,q4}; enum input{a,b}; int Accepted_states[FINAL_STATES]={q0}; char alphabet[ALPHABET_CHARCTERS]={'0','1'}; int Transition_Table[TOTAL_STATES][ALPHABET_CHARCTERS]; int Current_state=q0; void DefineDFA() {     Transition_Table[q0][0] = q0;     Transition_Table[q0][1] = q1;     Transition_Table[q1][0] = q2;     Transition_Table[q1][1] = q3;     Transition_Table[q2][0] = q4;     Transition_Table[q2][1] = q0;     Transition_Table[q3][0] = q1;     Transition_Table[q3][1] = q2;     Transition_Table[q4][0] = q3;     Transition_Table[

C program for DFA

DFA which accept the string (ab)*b (String ending with b). #include <stdio.h> #define TOTAL_STATES 4 #define FINAL_STATES 1 #define ALPHABET_CHARCTERS 2 #define UNKNOWN_SYMBOL_ERR 0 #define NOT_REACHED_FINAL_STATE 1 #define REACHED_FINAL_STATE 2 enum DFA_STATES{q0,q1,q2,q3}; enum input{a,b}; int Accepted_states[FINAL_STATES]={q2}; char alphabet[ALPHABET_CHARCTERS]={'a','b'}; int Transition_Table[TOTAL_STATES][ALPHABET_CHARCTERS]; int Current_state=q0; void DefineDFA() {     Transition_Table[q0][a] = q1;     Transition_Table[q0][b] = q2;     Transition_Table[q1][a] = q3;     Transition_Table[q1][b] = q0;     Transition_Table[q2][a] = q3;     Transition_Table[q2][b] = q3;     Transition_Table[q3][a] = q3;     Transition_Table[q3][b] = q3; } int DFA(char current_symbol) { int i,pos;     for(pos=0;pos<ALPHABET_CHARCTERS; pos++)         if(current_symbol==alphabet[pos])             break;//stops if symb