Posts

JavaScript syntax

  JavaScript syntax // How to create variables: var  x; let  y; // How to use variables: x =  5 ; y =  6 ; let  z = x + y; The two most important syntax rules for fixed values are: 1.  Numbers  are written with or without decimals: 10.50 1001 2. Strings are text, written within double or single quotes: example: "John Doe" 'John Doe' JavaScript Variables In a programming language,  variables  are used to  store  data values. JavaScript uses the keywords  var ,  let  and  const  to  declare  variables. An  equal sign  is used to  assign values  to variables. In this example, x is defined as a variable. Then, x is assigned (given) the value 6: example : let  x; x =  6 ; JavaScript Operators JavaScript uses arithmetic operators ( + - * / ) to compute values: example : JavaScript uses an assignment operator ( = ) to assign values to variables: example : let  x, y;...

JavaScript Statements

JavaScript Statements JavaScript statements are composed of: Values, Operators, Expressions, Keywords, and Comments. This statement tells the browser to write "Hello Dolly." inside an HTML element with id="demo":   let  x, y, z;     // Statement 1 x =  5 ;           // Statement 2 y =  6 ;           // Statement 3 z = x + y;       // Statement 4 Semicolons separate JavaScript statements. Add a semicolon at the end of each executable statement: let  a, b, c;   // Declare 3 variables a =  5 ;         // Assign the value 5 to a b =  6 ;         // Assign the value 6 to b c = a + b;     // Assign the sum of a and b to c

JavaScript

The JavaScript language Here we learn JavaScript, starting from scratch and go on to advanced concepts like OOP. We concentrate on the language itself here, with the minimum of environment-specific notes

Python Program to Find the Factorial of a Number

Python Program to Find the Factorial of a Number  # Python program to find the factorial of a number provided by the user. # change the value for a different result num = 7 # uncomment to take input from the user #num = int(input("Enter a number: ")) factorial = 1 # check if the number is negative, positive or zero if num < 0:    print("Sorry, factorial does not exist for negative numbers") elif num == 0:    print("The factorial of 0 is 1") else:    for i in range(1,num + 1):        factorial = factorial*i    print("The factorial of",num,"is",factorial)

Python Program to Print all Prime Numbers in an Interval

Python Program to Print all Prime Numbers in an Interval  # Python program to display all the prime numbers within an interval # change the values of lower and upper for a different result lower = 800 upper = 1000 # uncomment the following lines to take input from the user #lower = int(input("Enter lower range: ")) #upper = int(input("Enter upper range: ")) print("Prime numbers between",lower,"and",upper,"are:") for num in range(lower,upper + 1):    # prime numbers are greater than 1    if num > 1:        for i in range(2,num):            if (num % i) == 0:                break        else:            print(num) output: Prime numbers between 800 and 1000 are: 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 ...

Python Program to Check Prime Number

Python Program to Check Prime Number # Python program to check if the input number is prime or not num = 407 # take input from the user # num = int(input("Enter a number: ")) # prime numbers are greater than 1 if num > 1:    # check for factors    for i in range(2,num):        if (num % i) == 0:            print(num,"is not a prime number")            print(i,"times",num//i,"is",num)            break    else:        print(num,"is a prime number")        # if input number is less than # or equal to 1, it is not prime else:    print(num,"is not a prime number") output: 407 is not a prime number 11 times 37 is 407  In this program, variable num is checked if it's prime ...

Add Two Numbers Provided by The User

Add Two Numbers Provided by The User # Store input numbers num1 = input ( 'Enter first number: ' ) num2 = input ( 'Enter second number: ' ) # Add two numbers sum = float ( num1 ) + float ( num2 ) # Display the sum print ( 'The sum of {0} and {1} is {2}' . format ( num1 , num2 , sum ))      output:   Enter first number: 1.5 Enter second number: 6.3 The sum of 1.5 and 6.3 is 7.8

Python Program to Add Two Numbers

Python Program to Add Two Numbers # This program adds two numbers num1 = 1.5 num2 = 6.3 # Add two numbers sum = float(num1) + float(num2) # Display the sum print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))  output The sum of 1.5 and 6.3 is 7.8

Python Program to Print Hello world!

Python Program to Print Hello world! # This program prints Hello, world! print('Hello, world!')

C Program to Multiply two Matrices by Passing Matrix to a Function

C Program to Multiply two Matrices by Passing Matrix to a Function #include <stdio.h> void enterData(int firstMatrix[][10], int secondMatrix[][10], int rowFirst, int columnFirst, int rowSecond, int columnSecond); void multiplyMatrices(int firstMatrix[][10], int secondMatrix[][10], int multResult[][10], int rowFirst, int columnFirst, int rowSecond, int columnSecond); void display(int mult[][10], int rowFirst, int columnSecond); int main() {     int firstMatrix[10][10], secondMatrix[10][10], mult[10][10], rowFirst, columnFirst, rowSecond, columnSecond, i, j, k;     printf("Enter rows and column for first matrix: ");     scanf("%d %d", &rowFirst, &columnFirst);     printf("Enter rows and column for second matrix: ");     scanf("%d %d", &rowSecond, &columnSecond);     // If colum of first matrix in not equal to row of second matrix, asking user to enter the size of matrix agai...

C Program to Write a Sentence to a File

C Program to Write a Sentence to a File #include <stdio.h> #include <stdlib.h>  /* For exit() function */ int main() {    char sentence[1000];    FILE *fptr;    fptr = fopen("program.txt", "w");    if(fptr == NULL)    {       printf("Error!");       exit(1);    }       printf("Enter a sentence:\n");    gets(sentence);    fprintf(fptr,"%s", sentence);    fclose(fptr);    return 0; }  

C Program to Display its own Source Code as Output

C Program to Display its own Source Code as Output #include <stdio.h> int main() {     FILE *fp;     char c;     fp = fopen(__FILE__,"r");     do {          c = getc(fp);          putchar(c);     }     while(c != EOF);     fclose(fp);     return 0; }

Program to Display English Alphabets in Uppercase and Lowercase

Program to Display English Alphabets in Uppercase and Lowercase #include <stdio.h> int main() {     char c;     printf("Enter u to display alphabets in uppercase. And enter l to display alphabets in lowercase: ");     scanf("%c", &c);     if(c== 'U' || c== 'u')     {        for(c = 'A'; c <= 'Z'; ++c)          printf("%c ", c);     }     else if (c == 'L' || c == 'l')     {         for(c = 'a'; c <= 'z'; ++c)          printf("%c ", c);     }     else        printf("Error! You entered invalid character.");     return 0; }

C Program to Display Characters from A to Z Using Loop

C Program to Display Characters from A to Z Using Loop  #include <stdio.h> int main() {     char c;     for(c = 'A'; c <= 'Z'; ++c)        printf("%c ", c);        return 0; }

C Program to Find the Frequency of Characters in a String

C Program to Find the Frequency of Characters in a String #include <stdio.h> int main() {    char str[1000], ch;    int i, frequency = 0;    printf("Enter a string: ");    gets(str);    printf("Enter a character to find the frequency: ");    scanf("%c",&ch);    for(i = 0; str[i] != '\0'; ++i)    {        if(ch == str[i])            ++frequency;    }    printf("Frequency of %c = %d", ch, frequency);    return 0; }  Output Enter a string: This website is awesome. Enter a character to find the frequency: e Frequency of e = 4

C Program to Find the Length of a String

C Program to Find the Length of a String #include <stdio.h> int main () { char s [ 1000 ], i ; printf ( "Enter a string: " ); scanf ( "%s" , s ); for ( i = 0 ; s [ i ] != '\0' ; ++ i ); printf ( "Length of string: %d" , i ); return 0 ; }  

C Program to Copy String Without Using strcpy()

C Program to Copy String Without Using strcpy() #include <stdio.h> int main () { char s1 [ 100 ], s2 [ 100 ], i ; printf ( "Enter string s1: " ); scanf ( "%s" , s1 ); for ( i = 0 ; s1 [ i ] != '\0' ; ++ i ) { s2 [ i ] = s1 [ i ]; } s2 [ i ] = '\0' ; printf ( "String s2: %s" , s2 ); return 0 ; }  

program counts the number of bytes in a C source file

This program counts the number of bytes in a C source file. The program prompts the user for a file name and then concatenates the ".c" extension to this name. It uses the function getc to read the characters. #include<stdlib.h> #include<stdio.h> #include<string.h> main( ) { FILE* fptr; char extension[] = ".c"; char file_name[FILENAME_MAX]; /* defined in stdio.h*/ int char_count; printf("\n\n\tFile name (NO extension):\t"); scanf("%s",file_name); strcat(file_name,extension); fptr=fopen(file_name,"rb"); for(char_count=0; getc(fptr) !=EOF; ++char_count); printf("\n\tByte size:\t%d", char_count); fclose(fptr); return EXIT_SUCCESS; }

Invoke function without main in C Language

Invoke function without main in C Language. #include<stdio.h> #include<conio.h> #define FIRST   0 #define SECOND  1 #define THIRD   2 //Variables int a,b,c,ch; float d; //Function Prototype void Read(); void Operation(); void Display(); #pragma startup Read       0 //First_Priority #pragma startup Operation  1 //Second_Priority #pragma exit Display     //Third_Priority void main() {  printf(" Enter to main() ");  getch();  printf(" Exit From main() ");  getch(); } void Read() {  clrscr();  printf(" Enter the value of a : ");  scanf("%d",&a);  printf(" Enter the value of b : ");  scanf("%d",&b); } void Operation() {  printf(" ArithMetic Operations ");  printf("--------------------- ");  printf("1  -> Addition ");  printf("2  -> Subtraction ");  printf("3  -> Multiplication ");  printf("--...

Decimal to Binary, Octal and HEX converter

Decimal to Binary, Octal and HEX converter. #include<stdio.h> #include<conio.h> #define MAX 79 #define ESC 27 void main() {          char res,r;          int i,k=0,y;          long j=0,l=0,o=0;          textcolor(15);          for(i=0;i<5000;i++)                   cprintf(" ");          while(1)          {                   clrscr();                   printf("Enter Any Number To Be Converted : ");                   scanf("%ld",&j);   ...