• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
projectsgeek

ProjectsGeek

Download Mini projects with Source Code, Java projects with Source Codes

  • Home
  • Java Projects
  • C++ Projects
  • VB Projects
  • PHP projects
  • .Net Projects
  • NodeJs Projects
  • Android Projects
    • Project Ideas
      • Final Year Project Ideas
      • JSP Projects
  • Assignment Codes
    • Fundamentals of Programming Language
    • Software Design Laboratory
    • Data Structure and Files Lab
    • Computer Graphics Lab
    • Object Oriented Programming Lab
    • Assembly Codes
  • School Projects
  • Forum

Factorial,Greatest Number, Palindrome AWK

April 4, 2011 by ProjectsGeek 2 Comments

 

Factorial,Greatest Number,Palindrome String  using AWK Programming


Write a Menu driven program using AWK Programming for

 

a) Find factorial of a number.

b) Find greatest of three numbers

c) Find a prime numbers.

d) Find whether a number is palindrome

e) Find whether a string is palindrome

 f) Exit.

Factorial,Greatest Number,Palindrome AWK Programming Code

 

 

BEGIN{  
   print"main menu" ;  
   print"1.factorial of number" ;  
   print"2.greatest of numbers" ;  
   print"3.prime number" ;  
   print"4.palindrome of number" ;  
   print"5.palindrome of string" ;  
   print"enter ur choice" ;  
   getline ch<"-" ;  
   print ch ;  
   if(ch==1)  
   {  
    print "enter the number" ;  
    getline tmp<"-" ;  
    c=1 ;  
    while(tmp != 0)  
    {  
     c=c*tmp ;  
     tmp-- ;  
     }  
    print c ;  
    }  
   if(ch==2)  
   {  
    print "enter first number" ;  
    getline a1<"-" ;  
    print "enter second number" ;  
    getline a2<"-" ;  
    print "enter third number" ;  
    getline a3<"-" ;  
    if(a1>a2 && a1>a3)  
    print "first number is greater " ;  
    if(a2>a1 && a2>a3)  
    print "second number is greater " ;  
    if(a3>a1 && a3>a2)  
    print "third number is greater " ;  
    }  
    if(ch==3)  
    {  
     print "enter the number" ;  
     getline tmp<"-" ;  
     if(tmp==1)  
     print "not prime number" ;  
     i=tmp-1 ;  
     while(i > 1)  
     {  
      a=tmp%i ;  
      i--;  
      if(a == 0)  
      {  
       print "not prime number" ;  
       break ;      
      }  
     }  
      if(i==1)  
      print "prime number " ;  
     }  
     if(ch==4)  
     {  
      print "enter the number" ;  
      getline tmp<"-" ;  
      sd=0 ;  
      rev=" " ;  
      on=tmp ;  
      n=length(tmp)-1 ;  
      while(tmp != 0)  
      {  
        sd=tmp % 10 ;  
        tmp=tmp / 10;  
        rev=rev+(sd*(10^n)) ;  
        n-- ;  
       }  
      print rev ;  
      if(on == rev)  
       print "palindrome" ;  
      else  
      print "not palindrome" ;  
     }  
     if(ch==5)  
     {  
      print "enter the number" ;  
      getline tmp<"-" ;  
      p = ""  
      for(i=length(tmp); i > 0; i--) { p = p substr(tmp, i, 1) }  
      print p  
      if(p == tmp )  
      print "palindrome " ;  
      else  
      print "not palindrome" ;      
     }  
 }

 

Other Projects to Try:

  1. Factorial,Greatest Number,String Palindrome Shell code
  2. Student Database using AWK Programming
  3. string operations such as Copy, Length, Reversing, Palindrome, Concatenation
  4. Implement using Socket Programming (TCP/UDP) in Java
  5. Factorial of a number using recursion in C

Filed Under: Operating System . Linux Assignments

Reader Interactions

Comments

  1. Nishant says

    February 28, 2016 at 4:44 am

    I tried the string palindrome program, but looks like some edge case of ‘CR’ character is not handled, In my ssytem following worked fine (on ‘sh’ shell):

    awk ‘{

    rstr=””
    for(i = length($1)-1; i!=0; –i)
    rstr=rstr substr($1, i, 1);
    rstr=rstr “\r”;
    #print $1,rstr,length(rstr),length($1);
    if($1 == rstr)
    print rstr;
    }’

    Reply
    • ProjectsGeek says

      March 6, 2016 at 8:56 am

      Could you please let us know input you used ? and output you got ?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Tags

.Net Projects Download Android Project Ideas Android Projects Angular 2 Assembly Codes C # Projects C & C++ Projects C++ Projects Class Diagrams Computer Graphics Database Project Data Mining Projects DataScience Projects Datastructure Assignments Download Visual Basic Projects Electronics project Hadoop Projects Installation Guides Internet of Things Project IOS Projects Java Java Interview Questions Java Projects JavaScript JavaScript Projects java tutorial JSON JSP Projects Mechanical Projects Mongodb Networking Projects Node JS Projects OS Problems php Projects Placement Papers Project Ideas Python Projects seminar and presentation Struts

Search this Website


Footer

Download Java Project
Download Visual Basic Projects
Download .Net Projects
Download VB Projects
Download C++ Projects
Download NodeJs Projects
Download School Projects
Download School Projects
Ask Questions - Forum
Latest Projects Ideas
Assembly Codes
Datastructure Assignments
Computer Graphics Lab
Operating system Lab
australia-and-India-flag
  • Home
  • About me
  • Contact Form
  • Submit Your Work
  • Site Map
  • Privacy Policy