Sunday, 27 December 2020

Write a Program in C++ to input 3 Numbers and display the smallest number. Hint: Use min()

 #include<iostream>

#include<cmath>

using namespace std;

main()

    {

        int a,b,c,Min;

        cout<<"Enter 3 Numbers\n";

        cin>>a>>b>>c;

        Min=min(a,b);

        Min=min(Min,c);

        cout<<"Smallest Number= "<<Min;

    }

Saturday, 26 December 2020

Write a Program in Java to input 3 Numbers and display the smallest number. Hint: Use Math.min()

 import java.util.*;

class Min

{

    public static void main(String args[])

    {

        Scanner in=new Scanner(System.in);

        int a,b,c,min;

        System.out.println("Enter 3 Numbers");

        a=in.nextInt();

        b=in.nextInt();

        c=in.nextInt();

        min=Math.min(a,b);

        min=Math.min(min,c);

        System.out.println("Smallest Number= "+min);

    }

}

Write a Program in C++ to find out the Diagonal of a Square taking side of a Square as Input.

 #include<iostream>

#include<cmath>

using namespace std;

main()

    {

        double a,d;

        cout<<"Enter the side of the Square\n";

        cin>>a;

        d=sqrt(2)*a;

        cout<<"Side of the Square= "<<a<<"\n";

        cout<<"Diagonal of the Square= "<<d<<"\n";

    }

Write a Program in Java to find out the Diagonal of a Square taking side of a Square as Input.

import java.util.*;

class Diagonal

{

    public static void main(String args[])

    {

        Scanner in=new Scanner(System.in);

        double a,d;

        System.out.println("Enter the side of the Square");

        a=in.nextInt();

        d=Math.sqrt(2)*a;

        System.out.println("Side of the Square= "+a);

        System.out.println("Diagonal of the Square= "+d);

    }

}

/* Question: The final velocity of a vehicle can be calculated by using the formula:

V2=u2+2as;

where u= initial velocity, a=acceleration, s=distance covered

Write a Program in C++ to calculate and Display the final velocity by taking initial velocity, acceleration and the distance covered as inputs. */

#include<iostream>

#include<cmath>

using namespace std;

main()

    {

        int u,a,s;

        double v;

        cout<<"Enter the initial Velocity, acceleration and distance covered\n";

        cin>>u>>a>>s;

        v=sqrt((u*u)+(2*a*s));

        cout<<"Final Velocity = "<<v;

    }

 /* Question: The final velocity of a vehicle can be calculated by using the formula:

V2=u2+2as;

where u= initial velocity, a=acceleration, s=distance covered

Write a Program in Java to calculate and Display the final velocity by taking initial velocity, acceleration and the distance covered as inputs. */

import java.util.*;

public class Velocity

{

    public static void main(String args[])

    {

        Scanner in=new Scanner(System.in);

        int u,a,s;

        double v;

        System.out.println("Enter the initial Velocity, acceleration and distance covered");

        u=in.nextInt();

        a=in.nextInt();

        s=in.nextInt();

        v=Math.sqrt((u*u)+(2*a*s));

        System.out.println("Final Velocity = "+v);

    }

}

Friday, 25 December 2020

HTML Example with Explanation

<!DOCTYPE html>

<html>

<head>

<title>Page Title</title>

</head>

<body>


<h1>My First Heading</h1>

<p>My first paragraph.</p>


</body>

</html>


Example Explained

  • The <!DOCTYPE html> declaration defines that this document is an HTML5 document
  • The <html> element is the root element of an HTML page
  • The <head> element contains meta information about the HTML page
  • The <title> element specifies a title for the HTML page (which is shown in the browser's title bar or in the page's tab)
  • The <body> element defines the document's body, and is a container for all the visible contents, such as headings, paragraphs, images, hyperlinks, tables, lists, etc.
  • The <h1> element defines a large heading
  • The <p> element defines a paragraph

Write a program to find the sum and average of “N” numbers.

 import java.util.*;

class SUM_AVG

{

    public static void main(String args[])

    {

        Scanner in=new Scanner(System.in);

        int N,Num,Sum=0,avg;

        System.out.println("Enter the Number of Numbers");

        N=in.nextInt();

       for(int i=1;i<=N;i++)

      {

         System.out.println("Enter a Number");

         Num=in.nextInt();

         Sum=Sum+Num;

  }

   avg=Sum/N;

   System.out.println("Sum= "+Sum+"\n"+"Average= "+avg);

}

}

Write a program in C++ to find the sum and average of “N” numbers.

#include <iostream>

using namespace std;

main()

{

  int N,Num,Sum=0,avg;

  cout<<"Enter the Number of Numbers\n";

  cin>>N;

  for(int i=1;i<=N;i++)

  {

    cout<<"Enter a Number\n";

    cin>>Num;

    Sum=Sum+Num;

  }

   avg=Sum/N;

   cout<<"Sum= "<<Sum<<"\n"<<"Average= "<<avg;

}


Thursday, 24 December 2020

Write a program to find the sum of all the digits of a number using while statement.

#include <iostream>

using namespace std;

main()

{

  int N,d,Sum=0;

  cout<<"Enter a Number\n";

  cin>>N;

  while(N>0)

  {

    d=N%10;

    Sum=Sum+d;

    N=N/10;

  }

  cout<<"Sum= "<<Sum;

}


Wednesday, 23 December 2020

Write a Program in C++ to Accept a Word and Display it vertically.

 #include <iostream>

using namespace std;

main()

{

    string s; int i;

    cout<<"Enter a word or a sentence\n";

    cin>>s;

    for(i=0;i<s.length();i++)

    cout<<s.at(i)<<"\n";

}

Tuesday, 22 December 2020

Write a Program in C++ to Print :

/*
*
* *
* * *
* * * *
* * * * * 
*/
#include<iostream>
using namespace std;
main()
{
   for(int i=1;i<=5;i++)
   {
       for(int j=1;j<=i;j++)
       cout<<"* ";
       cout<<"\n";
   }
}

Wednesday, 16 December 2020

WAP in Java to print Hello World for infinite Times.

 public class Infinite

{

public static void main()

{

    for(;;)

    System.out.println("Hello World");

}

}

Tuesday, 15 December 2020

Write a Program in C++ to find the area of a Triangle when 3 sides are given

#include <iostream>

#include <cmath>

using namespace std;

main()

{

  float a,b,c,s,area;

  cout<<"Enter the 3 sides of a Triangle.\n";

  cin>>a>>b>>c;

  s=(a+b+c)/2;

  area= sqrt(s*(s-a)*(s-b)*(s-c));

  cout<<"Area= "<<area<<endl;

}


Write a Program in C++ to find the area and circumference of a circle

#include <iostream>

using namespace std;

main()

{

  float area,cir,r;

  cout<<"Enter the radius of the circle.\n";

  cin>>r;

  area=(22/7)*r*r;

  cir=2*(22/7)*r;

  cout<<"Area= "<<area<<endl;

  cout<<"Circumference= "<<cir<<endl;

}


Monday, 14 December 2020

C# Program to Print Hello World

using System;


public class Test

{

public static void Main()

{

Console.WriteLine("Hello World");

}

}


Write a Program in C++ to interchange the value of 2 variables without using third variable.

#include <iostream>

using namespace std;

main()

{

  int a,b;

  cout<<"Enter 2 Numbers"<<endl; 

  cin>>a>>b;

  cout<<"Before Swapping :\nThe first Number = "<<a<<endl;;

  cout<<"The Second Number = "<<b<<endl;

  a=a+b;

  b=a-b;

  a=a-b;

  cout<<"After Swapping :"<<endl;

  cout<<"The first Number = "<<a<<endl;

  cout<<"The second Number = "<<b<<endl;

}

Friday, 11 December 2020

Write a Program in C++ to interchange the value of 2 variables using third variable.

#include <iostream>

using namespace std;

main()

{

  int a,b,c;

  cout<<"Enter 2 Numbers"<<endl; 

  cin>>a>>b;

  cout<<"Before Swapping :\nThe first Number = "<<a<<endl;;

  cout<<"The Second Number = "<<b<<endl;

  c=a;

  a=b;

  b=c;

  cout<<"After Swapping :"<<endl;

  cout<<"The first Number = "<<a<<endl;

  cout<<"The second Number = "<<b<<endl;



C++ Program

  /* Question :-

A class contains 'b' number of boys and 'g' number of girls. On a rainy day, 'ba' number of boys and 'ga' number of girls are absent. Write a program to input the values of 'b', 'g', 'ba' and 'ga'. Calculate and display the following:

(i)  Percentage of girls present in the class.

(ii) Percentage of boys present in the class.

[Percentage must be calculated on the total number of Students]

*/


#include <iostream>

using namespace std;

    int main()

    {

    int b,g,ba,ga;

    float per_boys,per_girls;

    cout<<"Enter the number of boys and girls in the class\n";

    cin>>b>>g;

    cout<<"Enter the number of boys and girls in the class who were absent\n";

    cin>>ba>>ga;

    per_girls=(float)(g-ga)/(g+b)*100;

    per_boys=(float)(b-ba)/(g+b)*100;

    cout<<"The Percentage of girls Present in the class : "<<per_girls<<"%\n";

    cout<<"The Percentage of boys Present in the class : "<<per_boys<<"%\n";

    }

Program in Java using Input Stream Reader Class.

 /* Question :-

A class contains 'b' number of boys and 'g' number of girls. On a rainy day, 'ba' number of boys and 'ga' number of girls are absent. Write a program to input the values of 'b', 'g', 'ba' and 'ga'. Calculate and display the following:

(i)  Percentage of girls present in the class.

(ii) Percentage of boys present in the class.

[Percentage must be calculated on the total number of Students]

*/

import java.io.*;

class Class

{

    public static void main(String args[])throws IOException

    {

    InputStreamReader read=new InputStreamReader(System.in);

    BufferedReader in=new BufferedReader(read);

    int b,g,ba,ga;

    float per_boys,per_girls;

    System.out.println("Enter the number of boys and girls in the class");

    b=Integer.parseInt(in.readLine());

    g=Integer.parseInt(in.readLine());

    System.out.println("Enter the number of boys and girls in the class who were absent");

    ba=Integer.parseInt(in.readLine());

    ga=Integer.parseInt(in.readLine());

    per_girls=(float)(g-ga)/(g+b)*100;

    per_boys=(float)(b-ba)/(g+b)*100;

    System.out.println("The Percentage of girls Present in the class : "+per_girls+"%");

    System.out.println("The Percentage of boys Present in the class : "+per_boys+"%");

    }

}

Thursday, 10 December 2020

Write a Program in C++ to accept the number of Days and display the result of after converting it into number of years, number of months and the remaining number of days.

#include <iostream>

using namespace std;

main()

{

  int rem_days,years,months,days;

  cout<<"Enter the Number of Days\n";

  cin>>days;

  years=days/365;

  rem_days=days%365;

  months=rem_days/30;

  days=rem_days%30;

  cout<<"The number of Years: "<<years<<endl;

  cout<<"The number of Months: "<<months<<endl;

  cout<<"The number of Days: "<<days<<endl;

}


Thursday, 3 December 2020

Write a Program in C++ to Print the Floyd's Triangle

 /*

 Floyd's Triangle:

 1

 2 3

 4 5 6

 7 8 9 10

 11 12 13 14 15

 */

 #include<iostream>

 using namespace std;

 int main()

 {

   int i,j,p;

   for(i=1,p=1;i<=5;i++)

   {

       for(j=1;j<=i;j++)

       {

       cout<<p<<" ";

       p++;

       }

       cout<<endl;

   }

 }

Write a program in Java to Print Floyd's Triangle

 /*

 Floyd's Triangle:

 1

 2 3

 4 5 6

 7 8 9 10

 11 12 13 14 15

 */ 

public class Main

{

   public static void main (String[] args)

   {

   int i,j,p;

   for(i=1,p=1;i<=5;i++)

   {

       for(j=1;j<=i;j++)

       {

       System.out.print(p+" ");

       p++;

       }

       System.out.println();

   }

   }

    

}

Tuesday, 1 December 2020

Write a Program in C++ to Calculate Simple Interest by taking input from the User.

 #include<iostream>

using namespace std;

int main()

{

        double SI,P,R,T;

        cout<<"Enter The Principal, Rate and Time\n";

        cin>>P>> R>>T;

        SI=(P*R*T)/100.0;

        cout<<"The Simple Interest= "<<SI;

}

Write a Program in Java to Calculate Simple Interest by taking input from the User.

import java.util.*;

class Simple_Interest

{

    public static void main(String args[])

    {

        Scanner in=new Scanner(System.in);

        double SI,P,R,T;

        System.out.println("Enter The Principal, Rate and Time");

        P=in.nextDouble();

        R=in.nextDouble();

        T=in.nextDouble();

        SI=(P*R*T)/100.0;

        System.out.println("The Simple Interest= "+SI);

    }

}

Write a Program in Java to Accept a Word or a Sentence and Display it vertically.

import java.util.*;

class Vertical

{

    public static void main(String args[])

    {

        Scanner in=new Scanner(System.in);

        String s;

        System.out.println("Enter a String");

        s=in.nextLine();

        for(int i=0;i<s.length();i++)

        System.out.println(s.charAt(i));

    }

}

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...