# Programming

## Array functions toString, join, pop, push, shift and unshift

The toString function converts an array to a string by concatenation elements with commas in between. toString method Example 1: var a=Array(1,2,3); var s=a.toString(); s is “1,2,3” Example 2: var a = Array(1, “apple”, Math,Math.sqrt); var s = a.toString(); s is “1,apple,[object Math],function sqrt() { [native code] }” join method…

## Sum Of Digits In C

Q. How to make program of Sum Of digit (input-> 1,2,3 output->1+2+3=6) In C #include<stdio.h> #include<conio.h> #include<math.h> void main() { long num; int r,ans=0; clrscr(); printf(“Enter 5 digit Number:->>”); scanf(“%ld”,&num); while(num>0) { r=num%10; num=num/10; ans+=r; } printf(“\nAns=%d”,ans); getch(); } After Running Program 🙂

## Splice function in JavaScript

The splice function in JavaScript is used for adding, removing and returning elements from an array. Let us suppose we have an array var a=new Array(1,2,3,4,5); Splice with one parameter: This returns the elements of the array starting at the parameter. var b=a.splice(0); b=1,2,3,4,5. a=var b=a.splice(2): b=3,4,5 a=1,2 Splice with 2…

## Calculating Total and Percent By Using C

#include<stdio.h> #include<conio.h> void main () { float total,math,bio,phy,eng,comp,avg; clrscr(); printf(“Enter the value of your subject,math,bio,phy,eng,comp\n”); scanf(“%f%f%f%f%f”,&math,&bio,&phy,&eng,&comp); total=math+bio+phy+eng+comp; printf(“Your total number=%0.2f\n”,total); avg=total/5; printf(“Your percent=%0.2f %”,avg); getch(); } After Running Program 🙂

## Changing Kilometer into Meter,Centimeter,Inch,Foot,Yard&Mile By using C

#include<stdio.h> #include<conio.h> void main() { float kilometer,meter,centimeter,inch,foot,yard,mile; clrscr(); printf(“Enter your journey in kilometer=”); scanf(“%f”,&kilometer); meter=kilometer*1000; centimeter=100*meter; inch=centimeter/2.54; foot=inch/12; yard=foot/3; mile=yard/1760; printf(“Meter=%0.2f\nCentimeter=%0.2f\n”,meter,centimeter ); printf(“Inch=%0.2f\nFoot=%0.2f\nYard=%0.2f\nMile=%0.2f\n”,inch,foot,yard,mile); getch(); } After Running Program 🙂

## Reverse Number By Using C

#include<stdio.h> #include<conio.h> void main () { int num,rev=0,rem; clrscr(); printf(“Enter the Number=”); scanf(“%d”,&num); while(num!=0) { rem=num%10; rev=rev*10+rem; num=num/10; } if(num==0) printf( ” Reverse Number is=%d”,rev); getch(); } After Running Program 🙂

## Sort Function in JavaScript Arrays

The sort function in JavaScript Arrays allows performs sorting of array elements. Like all of JavaScript this function is remarkably flexible as well. Let us say we want to sort an array. var a=Array(4,5,3,-2); To sort you call a.sort(); This will sort the array numerically. -2,3,4,5 To change the sorting mode we…

## Arrays in JavaScript

An Array in JavaScript is a collection of items. The items can be accessed and modified. The whole array can be passed as a parameter to some function. Since JavaScript is typeless we can store data of any kind. The array automatically creates a variable called length which automatically gives the size…

## Simple Calculation In C

Question 1 Write a program to enter the selling price of a product. Add tax %and  insurance% cost. Calculate and print the final price. #include<stdio.h> #include<conio.h> #include<math.h> void main() { float cp,insurancepercent,taxpercent,finalprice,insurance,tax; clrscr(); printf(“Enter the cost price=”); scanf(“%f”,&cp); printf(“Enter insurance charge=”); scanf(“%f”,&insurancepercent); printf(“Enter tax=”); scanf(“%f”,&taxpercent); tax= taxpercent/100*cp; insurance=insurancepercent/100*cp; finalprice=tax +…

## Loops in JavaScript

JavaScript supports the 3 loops normally used in programming. The for loop, while loop and the do while loop. ForLoop Consider the following for loop: var output=””; for(var i=1;i<=10;i++) output=output + “,” + i; The four parts of this loop are: var i=1; Loop Initialization i<=10; Loop Condition output=output + “,” +…