Skip to main content

Top 20 Basic Program Questions and Answer's | OutPut- Technology369kk

Most Important 20+ Program use this same logic find all popular programming language such as C, C++,Python, Java, JavaScript and one so on. 


So In this post discuss most popular and famous Python, C, C++, Java and JavaScript  language used find program all program one by one. 
These program can be asked from basic use in array, string, pointer, list, loop, condition statement etc. chapter are similarly find all questions. 


Let's see the list of all basic program:

  • Write a program add two number. 
Hints How to Find :- c = a+b
Where a, b and c is variable. 
            print(c)

Program 
1. Python 
>>> a=10
>>> b=20
>>> c=a+b
>>> print(c)
30
>>> Done In Python

 

2. C and C++ 

// #include<iostream> // in C++

#include<stdio.h> // in C

#include<conio.h>

int main(){

int a= 10, b=20;

int c=a+b;

printf("Addition in C and C++", C);

 

3. Java

class add{
public static void main(String args[]){
int a=10,b=20;
int c= a+b;
System.out.println("Addition Value in Java: "+c);
}
}

4. JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Addition Program</title>
</head>
<body>
    <script>

        // Q1. Addition of two number
    //  var a =10;
    //  var b =20;
    //  var c =a+b;
    //  document.write("Addition Value is:-",+c);
   
// Get user input:-

     var num1 =parseInt(prompt("Enter 1st number:-"));
    var num2 =parseInt(prompt("Enter 2nd number:-"));
    var num3= num1 +num2;
    document.write("Additon value:-", num3);

    </script>
</body>
</html>


Note Important Point  for you:- Well Upper see Addition Program in Diff language like that, C, C++ , Python, Java and Java Script So you can watch all programming language logical are same just change in something syntax  in addition program so used this syntax in our program find given basic program, So Next question. 


Only JavaScript Language Solved all Program
  • 1. Write a program to calculate simple interest.
Hints :- Formula:- 
           Simple Interest = (P × R × T)/100  
Where P = Principal Amount, 
           R = Rate per Annum, 
           T = Time (years).

Program in JavaScript

   <!DOCTYPE html>
<html lang="en">
<head>
    <title>Addition Program</title>
</head>
<body>
    <script>

    var p=prompt("Enter p number:");
    var r=prompt("Enter r number:");
    var t=prompt("Enter t number:");
    var num1 = parseInt(p);
    var num2 = parseInt(r);
    var num2 = parseInt(t);
    var si=(p*r*t)/100;
        {
                document.write(si);
                document.write("<br>");
    }

    </script>
</body>
</html>
  • 2.Write a program to calculate area of circle
Hints :- Formula :- Ï€r².
Where:- Pi= 3.14
              R= radius.
Program in JavaScript

    let r =prompt("Enter radius number:-");
    let rad =parseInt(r);
    let  area=3.14*r*r;
    {
        document.write("<br>");
        document.write(area);

    }

  • 3. Write a program to calculate volume of sphere or area of sphere
Hints :- Formula :-  4/3 (Ï€)r³ and area of sphere is formula? :- 4·Ï€·r^2
Where :- 4/3 = 1.3333
                Ï€ = 22/7, or 3.144
                r= radius 

Program in JavaScript

    let r =prompt("Enter the volume of a sphere number:-");
    let rad =parseInt(r);
    let  sphere= 4/3*3.14*r*r*r;

    {
        document.write("<br>");
        document.write(sphere);
    }

  • 4. Write a program to calculate area of triangle.
Hints :- Formula :-  (1/2)*b*h
Where : 1/2= 0.5
            b= breath 
            h= height 

Program in JavaScript

    let base =prompt("Enter the base:-");
    let b=parseInt(base);
    let h=prompt("Enter the height:-");
    let height=parseInt(h);

    let artrg= 1/2*b*h;
    {
        document.write("<br>");
        document.write(artrg);
    }

  • 5. Write a program to calculate compound interest
Hints :- Formula :-  The formula to calculate the compound interest is given by: 

Compound Interest = Amount – Principal 

Where

Amount, A = P(1+(r/n))nt

Here, P = principal

r = rate of interest

t = time in years

n = number of times interest is compounded per year

Program in JavaScript

   
    var p=prompt("Enter principal value:");
    var r=prompt("Enter rate value :");
    var t=prompt("Enter time Y value :");
    var n=prompt("Enter Number of times interest is compounded per year value:");


    var num1 = parseInt(p);
    var num2 = parseInt(r);
    var num2 = parseInt(t);
    var num  =  parseInt(n);
    var a = p*1+(r/n)*n*t;

    var compInt = a-p;
    {
        document.write("<br> Your Total Amount is: ",a);  
     
// Used for document.writ inside --- console.log

        document.write("<br> And Compound Intrest:",compInt);
    }
  



  • 6. Write a program to swap value of two variable. 
Hints :- a=10,  b=20 
             swap= a+b;
            b=swap-b;
            a=swap-a;  
Program in JavaScript

    let a=10;
    let b=20;
    document.write("<br> Before swap ","a=",a," and ","b= ",b);
    let swap= a+b; //10+20=30
    b=swap-b;       // b: 30-20=10
    a=swap-a;        // a: 30-10 =20
    document.write("<br> After swap ","a=",a," and ","b= ",b);

    output :- a=20
              b=10
 

 

  • 7. Write a program to input two number and perform all arithmatic operation (addition,subtraction,multiplication,division,modulus) :- 
Hints:-  a=any number
              b=any number 
        
Program in JavaScript

var a=prompt("Enter 1st Number:-")
var b=prompt("Enter 2nd Number:-")
Well var, let and const work as same
let num1 = parseInt(a);
let num2 = parseInt(b);

const c= num1 + num2;
const d= num1 - num2;
const e= num1 * num2;
const f= num1 / num2;
const g= num1 % num2;
   
document.write("<br> Addition value: ",c);
document.write("<br> Substraction value: ",d);
document.write("<br> Multiplication value: ",e);
document.write("<br> Division value: ",f);
document.write("<br> Module value: ",g);
   

  • 8. write a program to input temperature in Celcious and convert to Fahrenheit:- Celcious to Fahrenheit conversion
Hints :- Formula :- ÂºF = (ºC x 9 / 5) + 32
where:- ÂºF = Fahrenheit.
             ÂºC =  Celcious
.
Program in JavaScript

var c = prompt("Enter temparture in celcuis: ");
var celcuis =parseInt(c);
var f = c*1.8+32;
document.write("<br> <hr>Farenheit Value is: ", f);

  • 9. write a program to input temperature in Fahrenheit and convert to Celcious :-

Hints :- Formula :- 
T(°C) = (T(°F) - 32) × 5/9
where:- ÂºF =  Fahrenheit.
             ÂºC =  Celcious.
               t is just a variable
Program in JavaScript

        
var f = prompt("Enter temparture in farenheit: ");
var fahrenheit =parseInt(f);
        // (32°F-32)×5/9
var c = (f-32)*5/9;
document.write("<br>Celcuis Value is: ",c);


  • 10.Write a program to find root of quadratic equation ax²+bx+c=0  
Hints :- 

Step 1:- var discriminant = bB* bB-4 * aA *cC;
Step 2:-  check 
if(discriminant > 0){
          var root1 = (-bB + sqrt( discriminant)) /(2 * aA);
          var root2 = (-bB+ sqrt( discriminant)) /(2 * aA);
         document.write("root1  and root2:  ", root1, root2);
}

Step 3:- check Otherwise this Condition 
 else if(discriminant == 0){
             var root1 = root2 = -bB / (2 *aA);
             document.write("root1 = root2 =", root1);
         }

Step4 :- Hence at last this is true:-
         else{
             var realPart = -bB /( 2 * aA);
             var imagPart = sqrt(- discriminant) / ( 2 * aA);
             document.write("Your realPart value and imagPart :-" , realPart, imagPart);
}

Program in JavaScript

       
var a = prompt("Enter a number");
var aA=parseInt(a);
var b = prompt("Enter a number");
var bB=parseInt(b);
var c = prompt("Enter a number");
var cC=parseInt(c);

var discriminant = bB* bB-4 * aA *cC;

if(discriminant > 0){
var root1 = (-bB + sqrt( discriminant)) /(2 * aA);
var root2 = (-bB+ sqrt( discriminant)) /(2 * aA);

document.write("root1  and root2:  ", root1, root2);
        }

else if(discriminant == 0){
var root1 = root2 = -bB / (2 *aA);
document.write("root1 = root2 =", root1);
}

else{
var realPart = -bB /( 2 * aA);
var imagPart = sqrt(- discriminant) / ( 2 * aA);
document.write("Your realPart value and imagPart :-"
realPart, imagPart);
}

  • 11. Write a program to input a number and check whether it is odd or even. :- 

Hints :-  if(a % 2==0) 

Program in JavaScript

var a= prompt("Enter a number");
var num1 =parseInt(a);
if(a % 2==0){
document.write("Output is even ")
}
else(
document.write("Output is Odd ")
    )

  • 12. Write a program to input 2 number and print the maximum number. :- 
Hints :-  Using Simple if else Statements
num1>num2
Check greater(>) than or less than (<)


Program in JavaScript

    var a= prompt("Enter 1st number");
    var num1 =parseInt(a);
    var b= prompt("Enter 2nd number");
    var num2 =parseInt(b);
    if(num1>num2){
        document.write("1st number is biggest ")
    }
    else(
        document.write("2nd number is biggest ")
    )

  • 13. write a program to input 3 number and print the highest number.  Same as print Q12  

Program in JavaScript

Hints :- Using Condition Statement but nested statement 

  
    var a= prompt("Enter 1st number");
    var num1 =parseInt(a);
    var b= prompt("Enter 2nd number");
    var num2 =parseInt(b);
    var c= prompt("Enter 3rd number");
    var num3 =parseInt(c);
    if (num1>num2){
        if(num1>num3){
            document.write("1st number is biggest");
        }
        else{
            document.write("3rd number is biggest");
        }
    }
    else{
        if(num2>num3){
            document.write("2nd number is biggest");
        }
        else{
            document.write("3rd number is biggest");
        }
    }

  • 14. Write a program to check inputing year is laep year or not.:-  

Hints :-  if(year % 4 == 0 && year % 100 != 0)

Program in JavaScript

    var y= prompt("Enter a number in year ");
    var year =parseInt(y);
    if(year % 4 == 0 && year % 100 != 0){
        document.write("This is leap year");
    }
    else{
        document.write("This is not leap year");
    }

15. write a program For to print 1 to 50  (Using all 3 loops) :-

Hints :-  Well three types of Loop :- for, while and do while.
1.Using For Loop:- 
for (initialization; Condition; Increment / Decrement){
// Statement 
}
for(a=1; a<=50 ;  a++){
}

2. Using While loop
 while(Condition){   
 print(a);
 a++;
}

3. Do While
do{
    print(a)

}while(Condition);

Program in JavaScript


var a=1;

//1. Using For Loop
for(a; a<=50;a++){
    document.write("<hr>","<br>",a)
}

// 2. Using While loop
while(a<=50){
    document.write("<hr>","<br>",a);
    a++;
}
//3.Using Do while Loop
do{
    document.write("<hr>","<br>",a)
    a++;
}while(a<=50);

  • 16. write a program to print 50 to 1 (Using all 3 loops)
HInts:-  Same as above hints question 15
 
for(num; num>=1; num--)  for used reverse print

Program in JavaScript


// 1. Using For Loop
for(num; num>=1; num--){
    document.write("<hr>","<br>",num)
}

// 2. Using whileLoop
while(num>=1){
    document.write("<br>",num)
    num--;
}

// 3.Using Do whileLoop
do{
    document.write("<br>",num);
    num--;
}while(num>=1);

  • 17. Write a program to print table of any inputted number.

Hints :- 

Program in JavaScript

   
    var num=parseInt(prompt("Enter any number:-"));
    for(var n=1; n<= 10;n++){
    document.write(num,"*",n,"=",num * n,"<br>");
    }


18.)Write a program to print following series 

Hints:- Work Is Progressing 

(a) 1,4,7,10.... up to 100 

Hints:- Using loop find program just skip 1 to 34 then so on display 1 to 100 

Program in JavaScript 


var t=1;
for(var i=1; i<=34; i++){
    document.write(t ," ");
    t=t+3;
}

// Output:- 1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55
58 61 64 67 70 73 76 79 82 85 88 91 94 97 100



(b) 1,4,7,10.... (15 terms)

Program in JavaScript

var t=1;
for(var i=1; i<=15; i++){
    document.write(t ," ");
    t=t+3;
}
// Output:- 1 4 7 10 13 16 19 22 25 28 31 34 37 40 43

(c) 1,4,9........ upto 100

Program in JavaScript

var t=1;
for(var i=1; i<=26; i++){
    document.write(t ," ");
    t=t+4;
}
// 1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61
65 69 73 77 81 85 89 93 97 101

(d) 1,8,27.... upto 1000

Program in JavaScript

Hints:- t= i ^3 

var t=1;
for(var i=1; i<=10; i++){
    t=i*i*i;
    document.write(t," ");
}
// Output:- 1 8 27 64 125 216 343 512 729 1000

(e) 1,1,2,3,5,8 .... upto 100

Program in JavaScript

Hints:- You Can Print same as fabonacci series.


var t1=1;
var t2=0;
for(var i=1; i<=20; i++){
    var t3=t1+t2;
    t1=t2;
    t2=t3;
    document.write(" ", t3);
}

// Output:- 1 1 2 3 5 8 13 21 34 55 89 144
233 377 610 987 1597 2584 4181 6765

(f) 1,1,2,3,5,8 .... (10 terms)

Program in JavaScript

Hints:- You Can Print same as fabonacci series. but only 10 times

var t1=1;
var t2=0;
for(var i=1; i<=10; i++){
    var t3=t1+t2;
    t1=t2;
    t2=t3;
    document.write(" ", + t3);
}
Output:- 1 1 2 3 5 8 13 21 34 55

  • 19) Fibonacci Series.
  • This is Fibonacci series 
  • Program in JavaScript
  • let n1=1, n2=0, n3,num;
    num=parseInt(prompt("Enter any number"));

    for(let i =1; i<=num;i++){
        n3=n1+n2;
        n1=n2;
        n2=n3;
        document.write(" <br>", n3);
    }

  • 20.) WAP Print any Factorial Number 

  • Program in JavaScript
  • var n=parseInt(prompt("Enter any factorail number: "));
    var fact =1;
    for(var i=1; i<=n; i++){ // Using loop print number of times
        fact = i* fact;
    }
    document.write("Your Factorail value is: ",fact);


  • 21.) WAP print Prime number yes or no.
  • Program in JavaScript


var num=parseInt(prompt("Enter any number: "));
var check=0;
for(var i=1; i<=num; i++){
    if(num%2==0){
        check++;
        break;
    }
}
if(check == 0){
    document.write(num , "Yes It is a prime Number");
}
else{
    document.write(num , " No It is not a prime Number");
}



  • 22) WAP Print 1st Sum of Natural Digits.
  • Program in JavaScript
  • var count,sum=0;
    var num=parseInt(prompt("Enter any number:"));
    for(count=1; count<=num; count++){
        sum=sum+count;
    }
    document.write("Total Sum is",sum);

  • 23.) WAP Print  Reverse Number.
  • Program in JavaScript

var reverse=0, rem;
var n=parseInt(prompt("Enter any number: "));
for(var rem=1; rem<n; rem++){
    rem=n%10;
    reverse = reverse * 10 + rem;
    n=n/10;
}
document.write("Your reversed number: ",reverse);




  • 21.)Palindrome number.
  • 23) Armstrong number.

Comments

Popular posts from this blog

Assignment of ITA/ Information Technology and Application BCA- Technology369kk

Q1. What is  computer Explain basic computer architecture and Difference components.  2. Discuss the use of memory in computer system, Explain memory hierarchy  in details. 3. What is software? Explain difference types of software with explain. 4. Write short notes on the given:- (I) Internet. (II) LAN (Local area network ) (III) Search engine (IV) Web browser  Q 1.What is computer Explain basic computer architecture, Difference components of computer.   Computer :- Computer is defined as an electronic device that takes input data and instructions from the user and after processing them, it generates useful and desired output quickly.   A computer is designed to execute applications and provides a variety of solutions through integrated hardware and software components.                            It is fast and automatic device. It works with the help of programs and represents the d...

C++ and Java Practical All Questions Answers - BCA -Technology369kk

C++ and Java  In this post see most important questions for practical questions given by college all questions with answers . Guys I want to say that this is only for suggested post for your practical please request to you change same alphabets, words or anything  methods name and variables name because if you write all words same then this is copy paste for another peoples.  Used Topics:  Keywords, Variables, Condition Statements, Function , Array, Structure, Pointer.                           In OOPs, Class and Objects, Constructor, Poly morph, Encapsulation, Access Specifiers,                               Inheritance etc.  So, Without Time Lose Come to the Points, let's go start Now:        *************************************************************************  C++ 12 ...

Assignment of PMO (Principal of Management and Organization) - Technology369kk

 ** Assignment Of PMO ** Agenda: -  4 Questions discuss in this post. Question 1. Write a d etails note on selection why it Called. negative process.  Question 2. Write a details note on 'span of control. Question 3. Planning is an essential process, do you agree ? Discuss  Question 4. Write a note on management function. Q 1. Write a d etails note on selection why it called negative process.  Ans :-  Selection is the process of choosing the most suitable candidates out of the several candidates available.          Selection is a negative process because there may be more rejected then those selected in most of the candidates that is called selection is a negative process. → Selection process has the following steps:-  [ A .] Screening of applicants - Based on the screening of applicants only those candidates. It Called further process of selection. Who are found eligible for the job Standards of the the organization. [ B .] S...