Sunday, August 9, 2020

Program to Find the nth Palindrome Number

 Palindrome Number: remains the same when it's reverse the digits.


Example:
               212
               717
              
Problem statement:-  Program to Find the nth Palindrome Number.

Data requirement:-

   Input Data:- rangenumber

   Output Data:- rangenumber, letest

   Additional Data:- cnum, num1, sum, rem, num2

Program in C

Here is the source code of the C Program to Find the nth Palindrome Number.

Code:

//Write a program to find the nth palindrome number.
#include <stdio.h>
int
main ()
{
  int i, rangenumber, num = 1, c = 0, latest = 0;
  printf ("Enter the Nth value:");
  scanf ("%d", &rangenumber);

  while (c != rangenumber)
    {
      int num1=num;
      int num2=0;
    while(num1!=0)
    {
        int rem=num1%10;
        num1/=10;
        num2=num2*10+rem;
    }
    if(num==num2)
      {
          c++;
          latest=num;
      }
      num = num + 1;
    }
  printf ("%dth palindrome number is %d", rangenumber, latest);
  return 0;
}

Input/Output:
Enter the Nth value:15
15th palindrome number is 66

Program in C++

Here is the source code of the C++ Program to Find the nth Palindrome Number.

Code:

#include <iostream>
using namespace std;
int
main ()
{
  int i, rangenumber, num = 1, c = 0, latest = 0;
  cout<<"Enter the Nth value:";
  cin>>rangenumber;

  while (c != rangenumber)
    {
      int num1=num;
      int num2=0;
      //reverse of number
    while(num1!=0)
    {
        int rem=num1%10;
        num1/=10;
        num2=num2*10+rem;
    }
    if(num==num2)
      {
          c++;
          latest=num;
      }
      num = num + 1;
    }
  cout<<rangenumber<<"th palindrome number is "<<latest;
  return 0;
}

Input/Output:
Enter the Nth value:19
19th palindrome number is 101

Program in Java
  
Here is the source code of the Java Program to Find the nth Palindrome Number.

Code:

import java.util.Scanner;
public class NthPalindromeNumber {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
int  rangenumber, num = 1, c = 0, latest = 0;
  System.out.println("Enter Nth number:");
  rangenumber=cs.nextInt();

  while (c != rangenumber)
    {
  int num1=num;
      int num2=0;
    while(num1!=0)
    {
        int rem=num1%10;
        num1/=10;
        num2=num2*10+rem;
    }
    if(num==num2)
      {
          c++;
          latest=num;
      }
      num = num + 1;
    }
 System.out.println(rangenumber+"th Palindrome Number is "+latest);
cs.close();
}
}

Input/Output:
Enter Nth number:
23
23rd Palindrome Number is 141

Program in Python
  
Here is the source code of the Python Program to Find the nth Palindrome Number.

Code:

rangenumber=int(input("Enter a Nth Number:"))
c = 0
latest = 0
num = 1
while c != rangenumber:
    num2=0
    num1 = num
    while num1 != 0:
        rem = num1 % 10
        num1 //= 10
        num2 = num2 * 10 + rem
    if num==num2:
        c+=1
        latest = num

    num = num + 1
print(rangenumber,"th Palindrome Number is ",latest)

Input/Output:
Enter an Nth Number:16
16 th Palindrome number is  77

Thursday, July 2, 2020

Write a program to calculate area of a rectangle and perimeter of a rectangle.


Write a C program to calculate the area and perimeter of a rectangle . or Write a program to calculate the area and perimeter of a rectangle  in C

Code:

/*Write a C program to calculate the area and perimeter of a rectangle . or Write a program to calculate the area and perimeter of a rectangle Using C*/

#include<stdio.h>

int main()
{
    double length,breadth;
    double area,perimeter;

    printf("Enter the length of rectangle:");
    scanf("%lf",&length);

    printf("Enter the breadth of rectangle:");
    scanf("%lf",&breadth);

    area=length*breadth;
    perimeter=2*(length+breadth);

    printf("Area of the rectangle = %0.2lf",area);
    printf("\nPerimeter of the rectangle = %0.2lf",perimeter);

    return 0;
}

Input/Output:

Enter the length of rectangle:5
Enter the breadth of rectangle:4
Area of the rectangle = 20.00
Perimeter of the rectangle = 18.00


Write a C++ program to calculate the area and perimeter of a rectangle . or Write a program to calculate the area and perimeter of a rectangle  in C++

Code:

/*Write a C++ program to calculate the area and perimeter of a rectangle . or Write a program to calculate the area and perimeter of a rectangle using C++*/

int main()
{
    double length,breadth;
    double area,perimeter;

    cout<<"Enter the length of rectangle:";
    cin>>length;

    cout<<"Enter the breadth of rectangle:";
    cin>>breadth;

    area=length*breadth;
    perimeter=2*(length+breadth);

    cout<<"Area = "<<area;
    cout<<"\nPerimeter = "<<perimeter;

    return 0;
}


Input/Output:

Enter the length of rectangle:7
Enter the breadth of rectangle:3
Area = 21
Perimeter = 20



Write a JAVA program to calculate the area and perimeter of a rectangle . or Write a program to calculate the area and perimeter of a rectangle  in Java

Code:

/*Write a JAVA program to calculate the area and perimeter of a rectangle . or Write a program to calculate the area and perimeter of a rectangle using Java*/

import java.util.Scanner;
public class AreaPerimeterRectangle {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);

double length,breadth;
    double area, perimeter;

    System.out.println("Enter the length of rectangle:");
    length=cs.nextDouble();

    System.out.println("Enter the breadth of rectangle:");
    breadth=cs.nextDouble();

    area=length*breadth;
    perimeter=2*(length+breadth);

    System.out.println("Area of the rectangle = "+area);
    System.out.println("Perimeter of the rectangle = "+perimeter);
    cs.close();

}

}


Input/Output:

Enter the length of rectangle:
7.5
Enter the breadth of rectangle:
8.0
Area of the rectangle = 60.0
Perimeter of the rectangle = 31.0




Write a PYTHON program to calculate the area and perimeter of a rectangle . or Write a program to calculate the area and perimeter of a rectangle  in Python

Code:


'''Write a Python program to calculate the area and perimeter of a rectangle .
or Write a program to calculate the area and perimeter of a rectangle using Python'''

length=int(input("Enter length of a rectangle :"))
breadth=int(input("Enter breadth of a rectangle :"))

area=length*breadth
perimeter=2*(length+breadth)

print("Area =",area)
print("Perimeter =",perimeter)


Input/Output:

Enter length of a rectangle :8
Enter breadth of a rectangle :5
Area = 40
Perimeter = 26

Write a Program to Calculate area and perimeter of a circle


Write a C program to calculate the area and perimeter of a circle . or Write a program to calculate the area and perimeter of a circle  in C

Code:

/*Write a C program to calculate the area and perimeter of a circle . or Write a program to calculate the area and perimeter of a circle Using C*/

#include<stdio.h>
int main()
{
    double radius;
    double area,perimeter;

    printf("Enter the radius of the circle:");
    scanf("%lf",&radius);

    area=3.14*radius*radius;
    perimeter=2*3.14*radius;

     printf("Area of the Circle = %0.2lf",area);
     printf("\nPerimeter of the Circle = %0.2lf",perimeter);

    return 0;
}



Input/Output:

Enter the radius of the circle:5
Area of the Circle = 78.50
Perimeter of the Circle = 31.40


Write a C++ program to calculate the area and perimeter of a circle . or Write a program to calculate the area and perimeter of a circle  in C++


Code:


/*Write a C++ program to calculate the area and perimeter of a circle . or Write a program to calculate the area and perimeter of a circle using C++*/

#include <iostream>

using namespace std;

int main()
{
    double radius;
    double area,perimeter;

    cout<<"Enter the radius of the circle:";
    cin>>radius;

    area=3.14*radius*radius;
    perimeter=2*3.14*radius;

    cout<<"Area of the Circle = "<<area;
    cout<<"\nPerimeter of the Circle = "<<perimeter;

    return 0;
}




Input/Output:

Enter the radius of the circle: 9
Area of the Circle = 254.34
Perimeter of the Circle = 56.52




Write a JAVA program to calculate the area and perimeter of a circle . or Write a program to calculate the area and perimeter of a circle  in Java


Code:

/*Write a JAVA program to calculate the area and perimeter of a circle . or Write a program to calculate the area and perimeter of a circle using Java*/

import java.util.Scanner;
public class AreaPerimeterCircle 
{

public static void main(String[] args) 
{
Scanner cs=new Scanner(System.in);
double radius;
    double area, perimeter;

    System.out.println("Enter the radius of the circle:");
    radius=cs.nextDouble();

    area=3.14*radius*radius;
    perimeter=2*3.14*radius;

     System.out.println("Area of the Circle = "+area);
     System.out.println("\nPerimeter of the Circle = "+perimeter);
       
     cs.close();
 
}
}


Input/Output:

Enter the radius of the circle:
11
Area of the Circle = 379.94

Perimeter of the Circle = 69.08




Write a PYTHON program to calculate the area and perimeter of a circle . or Write a program to calculate the area and perimeter of a circle  in Python

Code:


'''Write a Python program to calculate the area and perimeter of a circle.
or Write a program to calculate the area and perimeter of a circle using Python'''

radius=int(input("Enter radius of a circle :"))

area=3.14*radius*radius
perimeter=2*3.14*radius

print("Area =",area)
print("Perimeter =",perimeter)

Input/Output:

Enter radius of a circle : 4
Area = 50.24
Perimeter = 25.12

All the posts

Recent Posts

Program to Find the nth Palindrome Number

  Palindrome Number:  remains the same when it's reverse the digits . Example:                 212                717                Pro...