Posts

Identifier and Naming convention in python

Image
Python Keywords:                                                                            Keywords are reserved words for defining the syntax and structure of the Python language. Hence, you can not use them as identifier when naming variables, functions, objects, classes, and similar items or processes. In python there are 33 keywords and avoid using them as identifier to avoid errors or exceptions: Python Identifier:                     An identifier is a name given to a variable, class, function, string, list, dictionary, module, and other objects. It  differentiate one entity from another. Rules for writting Identifier : 1. Identifier cab be combination of any lower and upper lette...

C program to find the frequency of element in an array

Image
/* C program to find the frequency of each element of array */ #include <stdio.h> int main() {     int arr[100], freq[100];     int size, i, j, count;     /* Input size of array */     printf("\nEnter size of array: ");     scanf("%d", &size);     /* Input elements in array */     printf("\nEnter elements in array: ");     for(i=0; i<size; i++)         {         scanf("%d", &arr[i]);         /* Initially initialize frequencies to -1 */         freq[i] = -1;         }     for(i=0; i<size; i++)     {     count = 1;         for(j=i+1; j<size; j++)         { ...

C program that contains a string XOR each character in this string with 0 ,127

Write a C program that contains a string (char pointer) with a value \Hello World’. The program should XOR each character in this string with 0 and displays the result. Program: #include<stdlib.h> main() { char str[]="Hello World"; char str1[11]; int i,len; len=strlen(str); for(i=0;i<len;i++) { str1[i]=str[i]^0; printf("%c",str1[i]); } printf("\n"); } Q.2 Write a C program that contains a string (char pointer) with a value \Hello World’. The program should AND or and XOR each character in this string with 127 and display the result. PROGRAM: #include <stdio.h> #include<stdlib.h> void main() { char str[]="Hello World"; char str1[11]; char str2[11]=str[]; int i,len; len = strlen(str); for(i=0;i<len;i++) { str1[i] = str[i]&127; printf("%c",str1[i]); } printf("\n"); for(i=0;i<len;i++) { str3[i] = str2[i]^127; printf("%c",str3[i]); } pri...

JAVA Program for Twin Prime Number

Image
Twin Prime Number A twin prime is a prime number that is either 2 less or 2 more than another prime number.  Example- (5,7),  (11,13),  (17,19). In other words, a twin prime is a prime that has a prime gap of two. Sometimes the term twin prime is used for a pair of twin primes; an alternative name for this is prime twin or prime pair. Java Program : class TwinPrimes {     public static void main(String args[]) {         String primeNo = "";         int j = 0;         int LastPrime = 1;         System.out.println("Twin Primes are:");         for (int i = 1; i < 100; i++) {             for (j = 2; j < i; j++) {                if (i % j == 0) {            ...

Python Program to check two String are Anagram or not

Anagram An anagram is a word or phrase that's formed by rearranging the letters of another word or phrase. For example, the letters that make up “A decimal point” can be turned into the anagram “I'm a dot in place.” ... “Dormitory” turns into the anagram “dirty room,” Examples of anagram "restful" = "fluster" "funeral" = "real fun" "adultery" = "true lady" "customers" = "store scum" "forty five" = "over fifty" Python Program for Anagram String s1=input("Enter the First String: ") s2=input("Enter the Second String: ") def anagramCheck(s1, s2):           if(sorted(s1)== sorted(s2)):         print("The strings are anagrams.")      else:         print("The strings aren't anagrams.") anagramCheck(s1,s2)

Display Browser information using javascript

Q. Write a program using Java script for Web Page to display browsers information. Ans. <!DOCTYPE> <html> <head>     <title>Browsers information</title>   <script language=javascript>   function showBrowserinfo()   {     document.write("<b>Web Page to display browsers information</b> <br><br>");     document.write("Name "+navigator.appName+"<br>");     document.write("Version "+navigator.appVersion  +"<br>");     document.write("Codename " +navigator.appCodeName  +"<br>");     document.write("Cookie enable"+navigator.cookieEnabled  +"<br>");     document.write("Java Enable"+navigator.javaEnabled  +"<br>");     document.write("Mime type"+navigator.mimeTypes  +"<br>");     document.write("Platform"+navigator.platfo...

Armstrong Number in Javascript

Image
Q. Write a program in javascript to check given number is Armstrong or not ?  Ans.  An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 153 is an Armstrong number example -  153 = 1**3 + 5**3 +  3**3 = 1+125+27 => 153 Armsrong Number program in javascript <!doctype html> <html> <head> <script> function armstr() { var arm=0,a,b,c,d,num; num=Number(document.getElementById("no_input").value); temp=num; while(temp>0) { a=temp%10; temp=parseInt(temp/10); // convert float into Integer arm=arm+a*a*a; } if(arm==num) { alert("Armstrong number"); } else { alert("Not Armstrong number"); } } </script> </head> <body> Enter any Number: <input id="no_input"> <button onclick="armstr()">Check</button></br></br> </body> </html>