## C Program To Read Integer (N) And Print First Three Powers (N^1,N^2,N^3)

Problem :- Write A C Program To Read Integer (N) And Print First Three Powers (N^1,N^2,N^3) Example If user Enter a 5 From Keyboard Then Output Should be 5 ,25 ,125 Means power of number in 1 ,2 ,3

Logic :- For this problem We Need to multiply Number or we can use power function for that take a example for better understood this problem take a Number 5 as input and multiply with same number again like 5*5 for cube we need to again multiply with same number like 5*5*5 or we can use power function

Power Function  Syntax ;- for given example  xy .

pow(x,y)

also define the datatype of x and y .

Solution :-

Method 1 :- Simple Without Using Power Function

#include<stdio.h>
#include<math.h>
int main()
{
Visit http://www.programmingwithbasics.com/
*/
int num;
printf("\nEnter The Number .\n");
scanf("%d",&num);
printf("\nOutput Is\n\n");
printf("%d  ,%d  ,%d \n\n",num,num*num,num*num*num);
return 0;
}

Method 2 :- Using Power Function

#include<stdio.h>
#include<math.h>
int main()
{
Visit http://www.programmingwithbasics.com/
*/
int num,a,b,c;
printf("\nEnter The Number .\n");
scanf("%d",&num);
a=pow(num,1);
b=pow(num,2);
c=pow(num,3);
printf("\nOutput Is\n\n");
printf("%d  ,%d  ,%d \n\n",a,b,c);
return 0;
}

Output:-

## Java Program To Read Integer (N) And Print First Three Powers (N^1,N^2,N^3)

Problem :- Write A Java Program To Read Integer (N) And Print First Three Powers (N^1,N^2,N^3) Example If user Enter a 5 From Keyboard Then Output Should be 5 ,25 ,125 Means power of number in 1 ,2 ,3

Logic :- For this problem We Need to multiply Number or we can use power function for that take a example for better understood this problem take a Number 5 as input and multiply with same number again like 5*5 for cube we need to again multiply with same number like 5*5*5 or we can use power function

Power Function  Syntax ;- for given example  xy .

pow(x,y)

also define the datatype of x and y .

Solution :-

Method 1 :- Simple Without Using Power Function

Visit http://www.programmingwithbasics.com/
*/

import java.util.Scanner;

public class threenum
{
public static void main(String args[])
{
int num,a,b,c;
Scanner sc = new Scanner(System.in);

System.out.print("Enter The Number :\n\n");
num = sc.nextInt();
a=num;
b=num*num;
c=num*num*num;
System.out.println("\nOutput Is = " + a + " ,"+ b +" ,"+ c +"\n\n");

}
}

Method 2 :- Using Power Function

Visit http://www.programmingwithbasics.com/
*/

import java.util.Scanner;
import java.lang.*;
public class threenum1
{
public static void main(String args[])
{
int num;
double a,b,c;
Scanner sc = new Scanner(System.in);

System.out.print("Enter The Number :\n\n");
num = sc.nextInt();
a=Math.pow(num,1);
b=Math.pow(num,2);
c=Math.pow(num,3);
System.out.println("\nOutput Is = " + a + " ,"+ b +" ,"+ c +"\n\n");

}
}

Output:-

## C Program To Calculate Factorial Of A Given Number

Problem :- Write A C Program To Calculate Factorial Of A Given Number .

What Is Factorial :- In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,

5!=5*4*3*2*1=120.

The value of 0! is 1, according to the convention for an empty product*

The factorial operation is encountered in many areas of mathematics, notably in combinatorics, algebra, and mathematical analysis. Its most basic occurrence is the fact that there are n! ways to arrange n distinct objects into a sequence (i.e., permutations of the set of objects). This fact was known at least as early as the 12th century, to Indian scholars .
source :- Wikipedia

See Also :- C++ Program To Calculate Factorial Of A Given Number

Solution :-

Method 1 :- Factorial Using For Loop

#include<stdio.h>

int main()
{
Visit http://www.programmingwithbasics.com/
*/

unsigned long long int fact=1;
int i,num;

printf("Enter The Number. You Want Factorial  :");
scanf("%d",&num);

for(i=1;i<=num;i++)
{
fact=fact*i;
}

printf("\nFactorial is = %llu\n",fact);
return 0;

}

Output :-

## Java Program To Calculate Factorial Of A Given Number

Problem :- Write A Java Program To Calculate Factorial Of A Given Number .

What Is Factorial :- In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,

5!=5*4*3*2*1=120.

The value of 0! is 1, according to the convention for an empty product*

The factorial operation is encountered in many areas of mathematics, notably in combinatorics, algebra, and mathematical analysis. Its most basic occurrence is the fact that there are n! ways to arrange n distinct objects into a sequence (i.e., permutations of the set of objects). This fact was known at least as early as the 12th century, to Indian scholars .
source :- Wikipedia

See Also :- C Program To Calculate Factorial Of A Given Number

Solution :-

Method 1 :- Factorial Using For Loop

Visit http://www.programmingwithbasics.com/
*/

import java.util.Scanner;

public class factjava
{
public static void main(String args[])
{
int fact=1,num,i;
Scanner sc = new Scanner(System.in);

System.out.print("Enter The Number That You Want Factorial : \n\n");
num = sc.nextInt();

for(i=1;i<=num;i++)
{
fact=fact*i;
}

System.out.print("\nFactorial Is = "+fact);

}

}

Output :-

## C Program For Denomination of an Amount Using While Loop

Problem :- Write A C Program To Find Denomination Needed for A Given Amount Along With The Total Number of Notes .

Generally Notes are used in banks are given below in descending Order .Ii is dependent to country wise their are some country Denomination

INDIA ( Rupees )            USA ( Dollar )             INDIA ( Rupees )
( Before 8 Nov. 2016 )     ( Present )                        ( Present )

1000                                 100                                     2000
500                                    50                                        500
100                                    20                                        100
50                                      10                                          50
20                                        5                                          20
10                                        2                                          10
5                                          1                                            5
2                                                                                        2
1                                                                                        1

Logic :- The Logic Behind we have to divide a money by Above Money lets take a example Suppose money is 16108 then follow the Step We are taking a example of Indian Currency In present

Step 1:- Then First we divide 16108  by 2000 then we get 8    ,2000 rs notes then go to step 2

Step 2:-  After divide 2000 we get a remainder 108 The we know that 108 is not divisible by 500 so go to next step

Step 3:- Now divide 108 by 100 then we get ,100 rs note now remainder is 8 go to next step

Step 4:- 8 is divisible by 50 and 20 nor 10 so we escape now go to next step

Step 5:- Now divide 8 by 5 we get a 1 ,5 rs notes and remainder is 3 so go to next step

Step 6:- Now divide 3 by 2 we get 1 ,2 rs notes and remainder is 1

Step 7:- This is a Last step divide 1 by 1 we get zero remainder now print the total no of denomination needed and along with total no of count require to fulfill a requirement

So for 16108 You Need to

No.

8 * 2000 = 16000
1 * 100 = 100
1 * 5 = 5
1 * 2 = 2
1 * 1 = 1

Total =12 Notes For minimum Transaction

Solution :-

Method 1 :- Denomination For Indian Rupees

#include<stdio.h>
int main()

Visit http://www.programmingwithbasics.com/
*/
int amt, r2000=0, r500=0, r100=0, r50=0, r20=0, r10=0, r5=0, r2=0 , r1=0 ,count=0;

printf("Enter The Amount in Rupees : \n\n") ;
scanf("%d", &amt) ;

while(amt >= 2000)

r2000 = amt / 2000 ;
amt = amt % 2000;
printf("\nTotal Number Of 2000 Rupees Notes : %d", r2000) ;
break ;
}
while(amt >= 500)

r500 = amt / 500 ;
amt = amt % 500;
printf("\nTotal Number Of 500 Rupees Notes : %d", r500) ;
break ;

while(amt >= 100)

r100 = amt / 100 ;
amt = amt % 100;
printf("\nTotal Number Of 100 Rupees Notes : %d", r100) ;
break ;

while(amt >= 50)

r50 = amt / 50 ;
amt = amt % 50;
printf("\nTotal Number Of 50 Rupees Notes : %d", r50) ;
break ;
}
while(amt >= 20)

r20 = amt / 20 ;
amt = amt % 20;
printf("\nTotal Number Of 20 Rupees Notes : %d", r20) ;
break ;
}
while(amt >= 10)

r10 = amt / 10 ;
amt = amt % 10;
printf("\nTotal Number Of 10 Rupees Notes Or Coin : %d", r10) ;
break ;

while(amt >= 5)

r5 = amt / 5 ;
amt = amt % 5;
printf("\nTotal Number Of 5 Rupees Notes Or Coin : %d", r5) ;
break ;

while(amt >= 2)

r2 = amt / 2 ;
amt = amt % 2;
printf("\nTotal Number Of 2 Rupees Notes Or Coin : %d", r2) ;
break ;

while(amt >= 1)

r1 = amt / 1 ;
amt = amt % 1;
printf("\nTotal Number Of 1 Rupees Note Or Coin : %d", r1) ;
break ;
}
count = r2000 + r500 + r100 + r50 + r20 + r10 + r5 + r2 + r1;
printf("\n\nTotal Number Of Notes Require : %d\n", count) ;
return 0;
}

Method 2 :- Denomination For USA Dollar

#include<stdio.h>
int main()

Visit http://www.programmingwithbasics.com/
*/
int amt, r100=0, r50=0, r20=0, r10=0, r5=0, r2=0 , r1=0 ,count=0;

printf("Enter The Amount in Dollar : \n\n") ;
scanf("%d", &amt) ;

while(amt >= 100)

r100 = amt / 100 ;
amt = amt % 100;
printf("\nTotal Number Of 100 Dollar : %d", r100) ;
break ;

while(amt >= 50)

r50 = amt / 50 ;
amt = amt % 50;
printf("\nTotal Number Of 50 Dollar : %d", r50) ;
break ;
}
while(amt >= 20)

r20 = amt / 20 ;
amt = amt % 20;
printf("\nTotal Number Of 20 Dollar : %d", r20) ;
break ;
}
while(amt >= 10)

r10 = amt / 10 ;
amt = amt % 10;
printf("\nTotal Number Of 10 Dollar Or Coin : %d", r10) ;
break ;

while(amt >= 5)

r5 = amt / 5 ;
amt = amt % 5;
printf("\nTotal Number Of 5 Dollar Or Coin : %d", r5) ;
break ;

while(amt >= 2)

r2 = amt / 2 ;
amt = amt % 2;
printf("\nTotal Number Of 2 Dollar Or Coin : %d", r2) ;
break ;

while(amt >= 1)

r1 = amt / 1 ;
amt = amt % 1;
printf("\nTotal Number Of 1 Dollar Or Coin : %d", r1) ;
break ;
}
count = r100 + r50 + r20 + r10 + r5 + r2 + r1;
printf("\n\nTotal Number Of Dollar Require : %d\n", count) ;
return 0;
}

Output:-

## Java Program For Denomination of an Amount Using While Loop

Problem :- Write A Java Program To Find Denomination Needed for A Given Amount Along With The Total Number of Notes .

Generally Notes are used in banks are given below in descending Order .Ii is dependent to country wise their are some country Denomination

INDIA ( Rupees )            USA ( Dollar )             INDIA ( Rupees )
( Before 8 Nov. 2016 )     ( Present )                        ( Present )

1000                                 100                                     2000
500                                    50                                        500
100                                    20                                        100
50                                      10                                          50
20                                        5                                          20
10                                        2                                          10
5                                          1                                            5
2                                                                                        2
1                                                                                        1

Logic :- The Logic Behind we have to divide a money by Above Money lets take a example Suppose money is 16108 then follow the Step We are taking a example of Indian Currency In present

Step 1:- Then First we divide 16108  by 2000 then we get 8    ,2000 rs notes then go to step 2

Step 2:-  After divide 2000 we get a remainder 108 The we know that 108 is not divisible by 500 so go to next step

Step 3:- Now divide 108 by 100 then we get ,100 rs note now remainder is 8 go to next step

Step 4:- 8 is divisible by 50 and 20 nor 10 so we escape now go to next step

Step 5:- Now divide 8 by 5 we get a 1 ,5 rs notes and remainder is 3 so go to next step

Step 6:- Now divide 3 by 2 we get 1 ,2 rs notes and remainder is 1

Step 7:- This is a Last step divide 1 by 1 we get zero remainder now print the total no of denomination needed and along with total no of count require to fulfill a requirement

So for 16108 You Need to

No.

8 * 2000 = 16000
1 * 100 = 100
1 * 5 = 5
1 * 2 = 2
1 * 1 = 1

Total =12 Notes For minimum Transaction

Solution :-

Method 1 :- Denomination For Indian Rupees

Visit http://www.programmingwithbasics.com/
*/

import java.util.Scanner;

public class denomination
{
public static void main(String args[])
{
int amt, r2000=0, r500=0, r100=0, r50=0, r20=0, r10=0, r5=0, r2=0 , r1=0 ,count=0;
Scanner sc = new Scanner(System.in);

System.out.print("Enter The Amount in Rupees : \n\n");
amt = sc.nextInt();

while(amt >= 2000)

r2000 = amt / 2000 ;
amt = amt % 2000;
System.out.print("\nTotal Number Of 2000 Rupees Notes :"+ r2000) ;
break ;
}
while(amt >= 500)

r500 = amt / 500 ;
amt = amt % 500;
System.out.print("\nTotal Number Of 500 Rupees Notes : "+ r500) ;
break ;

while(amt >= 100)

r100 = amt / 100 ;
amt = amt % 100;
System.out.print("\nTotal Number Of 100 Rupees Notes : "+ r100) ;
break ;

while(amt >= 50)

r50 = amt / 50 ;
amt = amt % 50;
System.out.print("\nTotal Number Of 50 Rupees Notes : "+ r50) ;
break ;
}
while(amt >= 20)

r20 = amt / 20 ;
amt = amt % 20;
System.out.print("\nTotal Number Of 20 Rupees Notes : "+ r20) ;
break ;
}
while(amt >= 10)

r10 = amt / 10 ;
amt = amt % 10;
System.out.print("\nTotal Number Of 10 Rupees Notes Or Coin : "+ r10) ;
break ;

while(amt >= 5)

r5 = amt / 5 ;
amt = amt % 5;
System.out.print("\nTotal Number Of 5 Rupees Notes Or Coin : "+ r5) ;
break ;

while(amt >= 2)

r2 = amt / 2 ;
amt = amt % 2;
System.out.print("\nTotal Number Of 2 Rupees Notes Or Coin : "+ r2) ;
break ;

while(amt >= 1)

r1 = amt / 1 ;
amt = amt % 1;
System.out.print("\nTotal Number Of 1 Rupees Note Or Coin : "+ r1) ;
break ;
}
count = r2000 + r500 + r100 + r50 + r20 + r10 + r5 + r2 + r1;
System.out.print("\n\nTotal Number Of Notes Require : \n\n"+ count) ;
}
}

Method 2 :- Denomination For USA Dollar

Visit http://www.programmingwithbasics.com/
*/

import java.util.Scanner;

public class denominationusa
{
public static void main(String args[])
{
int amt, r100=0, r50=0, r20=0, r10=0, r5=0, r2=0 , r1=0 ,count=0;
Scanner sc = new Scanner(System.in);

System.out.print("Enter The Amount in Dollar : \n\n");
amt = sc.nextInt();

while(amt >= 100)

r100 = amt / 100 ;
amt = amt % 100;
System.out.print("\nTotal Number Of 100 Dollar : "+ r100) ;
break ;

while(amt >= 50)

r50 = amt / 50 ;
amt = amt % 50;
System.out.print("\nTotal Number Of 50 Dollar : "+ r50) ;
break ;
}
while(amt >= 20)

r20 = amt / 20 ;
amt = amt % 20;
System.out.print("\nTotal Number Of 20 Dollar : "+ r20) ;
break ;
}
while(amt >= 10)

r10 = amt / 10 ;
amt = amt % 10;
System.out.print("\nTotal Number Of 10 Dollar Or Coin : "+ r10) ;
break ;

while(amt >= 5)

r5 = amt / 5 ;
amt = amt % 5;
System.out.print("\nTotal Number Of 5 Dollar Or Coin : "+ r5) ;
break ;

while(amt >= 2)

r2 = amt / 2 ;
amt = amt % 2;
System.out.print("\nTotal Number Of 2 Dollar Or Coin : "+ r2) ;
break ;

while(amt >= 1)

r1 = amt / 1 ;
amt = amt % 1;
System.out.print("\nTotal Number Of 1 Dollar Or Coin : "+ r1) ;
break ;
}
count = r100 + r50 + r20 + r10 + r5 + r2 + r1;
System.out.print("\n\nTotal Number Of Dollar Require : \n\n"+ count) ;
}
}

Output:-

## Java Program To Find Greatest Among Three Numbers

Problem :- Write A C++ Program To Find Greatest Among Three Numbers .Take three numbers from user and print the greatest number among them ex :- three numbers are 10 ,20 ,30 then 30 is greatest show 30 in output screen .

Logic :- For this problem there is a simple logic that take all three numbers and choose one number and compare that number to rest of the two number is number is greatest then print else choose second number and repeat the previous process if greatest then print second number is greatest else go to third number and repeat the same process .We are taking a Example and check all the process Step by Step

Example :- We are taking a Three number 55,65,75 as Input

Step 1 :- Select first number 55 and compare to 65 and 75 as we know 55 is not greater so control transfer to second condition .

Step 2 :- Now choose Second number 65 and compare to 55 and 75 as we know 65 is greater that 55 but not greater than 75 so control transfer to Third condition .

Step 3 :- Now choose Third number 75 and compare to 65 and 55 as we know 75 is greater compare both number 55 and 65 .Now we have a greatest number then print the number

Step 4 :- This is a Special Step if all condition didn't Match then All Number are equal .Example :- 50 ,50 ,50  then control goes to last condition and program  Output is "All Are Equal "

Solution :-

Method 1:-

Visit http://www.programmingwithbasics.com/
*/

import java.util.Scanner;

class GreatestAmongThree
{
public static void main(String[] args)
{
int num1,num2,num3;
Scanner scan=new Scanner(System.in);
System.out.println("Enter Three Numbers: ");
num1=scan.nextInt();
num2=scan.nextInt();
num3=scan.nextInt();

if(num1>=num2 && num1>=num3)
{
System.out.println("Greatest Number Is : "+num1);
}
else if(num2>=num1 && num2>=num3)
{
System.out.println("Greatest Number Is : "+num2);
}
if(num3>=num1 && num3>=num2)
{
System.out.println("Greatest Number Is : "+num3);
}
}

}

Method 2:-Find Greatest Using Ternary Operator

Visit http://www.programmingwithbasics.com/
*/

import java.util.Scanner;
class GreatestAmongThree
{
public static void main(String[] args)
{
int num1,num2,num3,Greatest;

Scanner scan=new Scanner(System.in);
System.out.println("Enter Three Numbers: ");

num1=scan.nextInt();
num2=scan.nextInt();
num3=scan.nextInt();

Greatest=(num1>num2)?(num1>num3?num1:num3):(num2>num3?num2:num3);
System.out.println("Greatest Number Is : "+Greatest);
}

}

Output:-

## C Program To Find Greatest Among Three Numbers

Problem :- Write A C++ Program To Find Greatest Among Three Numbers .Take three numbers from user and print the greatest number among them ex :- three numbers are 10 ,20 ,30 then 30 is greatest show 30 in output screen .

Logic :- For this problem there is a simple logic that take all three numbers and choose one number and compare that number to rest of the two number is number is greatest then print else choose second number and repeat the previous process if greatest then print second number is greatest else go to third number and repeat the same process .We are taking a Example and check all the process Step by Step

Example :- We are taking a Three number 55,65,75 as Input

Step 1 :- Select first number 55 and compare to 65 and 75 as we know 55 is not greater so control transfer to second condition .

Step 2 :- Now choose Second number 65 and compare to 55 and 75 as we know 65 is greater that 55 but not greater than 75 so control transfer to Third condition .

Step 3 :- Now choose Third number 75 and compare to 65 and 55 as we know 75 is greater compare both number 55 and 65 .Now we have a greatest number then print the number

Step 4 :- This is a Special Step if all condition didn't Match then All Number are equal .Example :- 50 ,50 ,50  then control goes to last condition and program  Output is "All Are Equal "

Solution :-

Method 1:-

#include <stdio.h>
int main()
{
Visit http://www.programmingwithbasics.com/
*/
double num1, num2, num3;

printf("Enter Three Numbers: ");
scanf("%lf %lf %lf", &num1, &num2, &num3);

if (num1>=num2)
{
if(num1>=num3)
printf("%.2lf Is The Largest Number. ", num1);
else
printf("%.2lf Is The Largest Number. ", num3);
}
else
{
if(num2>=num3)
printf("%.2lf Is The Largest Number. ", num2);
else
printf("%.2lf is the largest number.",num3);
}

return 0;

}

Method 2:-

#include<stdio.h>

int main()
{
Visit http://www.programmingwithbasics.com/
*/
double num1, num2, num3;

printf("Enter Three Numbers: \n");
scanf("%lf %lf %lf", &num1, &num2, &num3);

if (num1 > num2 && num1 > num3)
printf("\nGreatest Number Is :%lf",num1);

else if (num2 > num3 && num2 > num1)
printf("\nGreatest Number Is :%lf",num2);

else if (num1 > num1 && num3 > num2)
printf("\nGreatest Number Is :%lf",num1);

else if ((num1==num2) && (num2==num3) && (num3==num1))
printf("\nAll Are Equal");

}

Output:-