31/10/2015

C++ Program To Check Evenness And Oddness In An Array
Problem:- Program To Check Each Element of a 1-D Integer Array For Evenness / Oddness. Means you have to find even and odd number in an array.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- If the number is divided by 2 then the number is an even number if not the number is odd. So we divide the number of an array one by one of an array if number divide by 2 and reminder is zero then the number is even and if the remainder is not zero then the number is odd. Check here C++ Program To Find Number Is Even Or Odd Using Pointer then proceed for an array.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post


Solution:-

#include<iostream>
using namespace std;
int main()
{
  int a[100],i,n,sum=0;
 
cout<<"Enter The Size of Array\n";
  cin>>n;

  cout<<"Enter The Element\n";
  for(i=0;i<n;i++)
  {
  cin>>a[i];
  }
  cout<<"Elment in Array is Given Below\n";
  for(i=0;i<n;i++)
  {
  if(i%2==0)
  cout<<"Evenness  \n"<<a[i]<<"  ";
  else
  cout<<"Oddness  \n"<<a[i]<<"  ";
  }
 return 0;

}

Output:-

C++ Program To Check Evenness And Oddness In An Array


You May Also See

1. C++ Program For Temperature Conversion Celcius To Fahrenheit And Vice Versa Using Switch Case

2. C++ Program To Find A Grade Of Given Numbers Using Switch Case

3. C++ Program To Perform All Arithnatic Operations Ie:-(a+b,a-b,a*b,a/b,a%b) Using Switch Case

4. C++ Program To Print A Reverse Order Of Any Number Using Loop

5. C++ Program Print Truth Table Of XY+Z Using Loop

6. C++ Program Convert Decimal Number To Binary Number Using Loop

7. C++ Program To Print The Fibonacci Series Up to Given Number Of Terms



C++ Program To Reverse An Array And Sum Of Its Element
Problem:- Program to read the 1D array, Display its elements in reverse order and print the sum of the elements or easier way to reverse array c++ or c++ reverse array elements or how to print an array backward in c or print array in reverse order java or print 2n lines in reverse order c++ or print array in reverse order javascript or c++ program for printing 2n lines in reverse sequence or how to print the content of a file in reverse order in c++.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.


Explanation:- You can print array element from the last index to zero'th index and add all elements of an array and while you are reversing the array also add all variables of an array and keep the sum in and at the end of the program print the sum of all variable of an array. check here how to reverse element in array C++ Program Reverse An Array In O(n).

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post.

Solution:-

#include<iostream>
using namespace std;
int main()
{
  int a[100],i,n,sum=0;

  cout<<"Enter The Size of Array\n";
  cin>>n;
 
cout<<"Enter Element Of Array\n";
  for(i=0;i<n;i++)
  {
  cin>>a[i];
  }

  cout<<"Elment in Array is Given Below\n";
  for(i=(n-1);i>=0;i--)
  {
  cout<<a[i]<<"  ";
  sum=sum+a[i];
  }
  cout<<"\n\nSum Of Array Is = "<<sum;
 return 0;

}

Output:-

C++ Program To Reverse An Array And Sum Of Its Element


You May Also See


1. C++ Program To Check Number Is Positive Or Negative

2. C++ Program To Find Character Is Vowel Or Not

3. C++ Program To Calculate Factorial Of A Given Number



C++ Program To Print Element Of An Array
Problem :- Write A Program To Print Element Of An Array

Logic :- Just take a input from user and print all the element of array after that you can reverse check how C++ Program To Reverse An Array Sum Of Its Element

Solution :-

#include<iostream>
using namespace std;
int main()
{
//By-Ghanendra Yadav 
  int n,a[50],i;
 
  cout<<"Enter The Size Of Array: \n";
  cin>>n;
 
  cout<<"Enter The Element Of Array: \n";
  for(i=0;i<n;i++)
  {
  cin>>a[i];
}
 
  cout<<"Output Of Array: ";
  for(i=0;i<n;i++)
  {
  cout<<a[i]<<"  ";
}
 return 0;
}

Output:-


C++ Program To Print Element Of An Array

C++ Program To Print A Table Using For Loop
Problem :- Write C++ A Program To Print A Table Of Given Number Using For Loop

Logic :- Take A for loop and initialize with number you taken from user and put a condition that number multiply with 10 and in last condition increase a number by number see below

Syntax :- 

for(=number;i<=number*10;i=i+number)
cout<<i;

Solution :-

#include<iostream>
using namespace std;
int main()
{
    int i,num;
    
    cout<<"Enter Any Number To Print Table \n";
    cin>>num;
    
    for(i=num;i<=10*num;i=i+num)
    {
        cout<<i<<endl;
    }
    return 0;

}

Output:-


C++ Program To Print A Table Using For Loop

C++ Program To Find The HCF Or LCM Of Given Number
Problem :- Write A C++ Program To Find The HCF (Highest Common Factor) Or LCM (least Common Multiple) Of Two Number

Logic :- Logic Is very simple check in code if you find any difficulty comment below you also check Geeksforgeeks Solution For " GCD of Array "

Solution :-

#include<iostream>
using namespace std;
int main()
{
//By-Ghanendra Yadav
  int a,b,hcf,lcm,max,min,r;
 
  cout<<"Enter Two Numbers: \n";
  cin>>a>>b;

if(a>b)
{
  max=a;
  min=b;
}
else if(b>a)
{
  max=b;
  min=a;
}
if(a==b)
  hcf=a;
else
{
  do
  {
  r=max%min;
  max=min;
  min=r;
  }while(r!=0);
  hcf=max;
}
  lcm=(a*b)/hcf;
  cout<<"\nLCM = "<<lcm<<"\nHCF = "<<hcf;
  return 0;
}

Output:-

C++ Program To Find The HCF Or LCM Of Given Number

C++ Program To Check Year Is Leap Year Or Not
Problem :- Write A Program To Check Year Is Leap Year Or Not .Means Year Has 366 Days in Year .

Logic :- We Know that leap year have 366 Days in a year ,so if year is divide by 4 and 400 then year is leap year or one more condition if year divide by 100 then Year Is Not leap year or Leap Year Comes Every 4 Years Like 
1992 ,1996 ,2000 ,2004 ,2008 ,2012 ,2016 ,2020 These are leap Years. 

Solution :-

#include<iostream>
using namespace std;
int main()
{
//By-Ghanendra Yadva
int year;

cout<<"Enter The Year You Want To Check : \n";
cin>>year;
if((year%4)==0 && (year%400)==0)
{
cout<<"\nYear Is Leap Year\n";
}
else if(year%100==0)
cout<<"\nYear Is Not Leap Year\n";
else
cout<<"\nYear Is Leap Year\n";
return 0;
}

Output:-

C++ Program To Check Year Is Leap Year Or Not

C++ Program To  Find Max Number Among Given Three Number
Problem :- Write A Program To  Find Max Number Among Given Three Number

Logic :- This Is a different logic to find max number among three number .

Step 1:- we use forth variable as 'max' and store first element in max then compare max to next to element 

Step 2 :- if second number is greater than max then store second number in max if it is less then compare with third element

Step 3 :- If third number is greater then store third element in max if condition fails then first number is greater

Solution :- 

#include<iostream>
using namespace std;
int main()
{
  int x,y,z,max;

  cout<<"Enter The Three Numbers \n";
  cin>>x>>y>>z;

  max=x;
if (y>max)
  {
  max=y;
}
if(z>max)
  {
  max=z;
}
cout<<"\nThe Greatest Number In Given Numbers "<<x<<" "<<y<<"  "<<z<<" is "<<max;

}

Output:- 

C++ Program To  Find Max Number Among Given Three Number

C++ Program To Convert A Lower Case To Upper Case Or Vice-Versa
Problem :- Write A Program To Convert A Lower Case To Upper Case Or Vice-Versa

Logic :- Convert Lower to upper and upper to lower .we use ASCII value as we know that 'a' to 'z' ASCII is '97' to '122' And 'A' to 'Z' ASCII is '65' to '90' .
so if want to convert lower to upper then minus 32 to character 
and if you want to convert upper to lower then add 32 to character .

Solution :-

#include<iostream>
using namespace std;
int main()
{
  //By-Ghanendra Yadav
  char ch;
  cout<<"Enter any Alphabet :\n";
  cin>>ch;

if(ch>='a'&&ch<='z')
{
  cout<<"\nYou Entered A Lowercase Alphabet\n";
  ch=ch-32;
  cout<<"\nThe uppercase alphabet is "<<ch;
}
else
{
  cout<<"\nYou Entered An Uppercase Alphabet\n";
  ch=ch+32;
  cout<<"\nTe Lowercase Alphabet Is "<<ch;
}
cout<<endl;
return 0;

}

Output:-

C++ Program To Convert A LowerCase To UpperCase Or Vice-Versa

C++ Program To Find Quotient And Reminder Of Two Numbers
Problem :- Write A Program To Find Quotient And Reminder Of Two Numbers .

Logic :- This is very Easy as we know then divide any number using ' / ' operator then it will print ' Quotient 'and if you use ' % " then it will print Reminder . 

Solution :-

#include<iostream>
using namespace std;
int main()
{
//by-Ghanendra Yadav 
  int a,b,q,r;

  cout<<"Enter Two Numbers : \n";
  cin>>a>>b;

if(a>b)
{
  q=a/b;
  r=a%b;
  cout<<"\nQuotient="<<q;
  cout<<"\nRemainder="<<r;
}
else
  {
  cout<<"\nFirst Number. Should Be Greater Than Second Number….!!!";
}
 return 0;

}

Output:-

C++ Program To Find Quotient And Reminder Of Two Numbers

C++ Program To Check Number Is Armstrong Or Not
Problem :- Write A Program To Check Number Is Armstrong Or Not

Armstrong Number :- An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371 source Click Here

Logic :- Logic is very simple you have to you have to separate all digit and sum of the cube of digit find 
Example :- let's check 371  
then divide by 10 we got 371/10=1 .cube of 1 is 1 store this result and again divide by 10 we got 37/10=7 . cube of 7 is 343 store and add to previously got result 1 so now its become 344  ,again divide by 10 we got 3/10=3 cube of 3 is 27 ,Now again add 27+344=371
so the Number is Armstrong Number 

Note :- Divide the number by 10 until it become Zero

Solution :-

#include<iostream>
using namespace std;
int main()

  //By-Ghanendra Yadav
  int i,n1,num=0,n2,rem;

  cout<<"Enter The Number :\n";
  cin>>n1;
 
n2=n1;
  while(n1!=0)
  {
  rem=n1%10;
  num=num+rem*rem*rem;
  n1=n1/10;
  }
  if(num==n2)
  cout<<"Number is Armstrong\n";
  else
  cout<<"Number is not Armstrong\n";
 return 0; 

}

Output:-

C++ Program To Check Number Is Armstrong Or Not

21/10/2015

Large Fibonacci Numbers in C++ | Big Fibonacci Series
Write A Program To Find the Large Fibonacci Numbers in C++. For Print Fibonacci Series We Use Simple Method. As we know the Fibonacci Series is started with Zero (0) and the next Element is One Then we add the previous two elements and print the next element of the Fibonacci Series.

Fibonacci Series start with a Zero and the next element is one then first we print 0 and 1. Now add two previous elements and print the next element as 0+1=1. Repeat that process Until the nth term. Large Fibonacci Numbers in C++ are up to 10 Elements below

Fibonacci Series: 0 ,1 ,1 ,2 ,3 ,5 ,8 ,13 ,21 ,34 .

Large Fibonacci Numbers in C++


#include <iostream>
using namespace std;
int main()
{
	int n, a, b, i;

	cout << "How Many Term You Want To Check :\n";
	cin >> n;

	long long A[n];
	a = 0;
	b = 1;
	cout << "The Large Fibonacci Numbers Are :\n";

	if (n < 2)
	{
		A[0] = a;
		A[1] = b;
		cout << A[0] << ", " << A[i];
	}
	else
		A[0] = a;
	A[1] = b;

	cout << A[0] << ", " << A[1] << ", ";

	for (i = 2; i < n; i++)
	{
		A[i] = A[i - 1] + A[i - 2];;
		cout << A[i] << ", ";
	}

	return 0;

}

Large Fibonacci Numbers Output


Large Fibonacci Numbers Output

Similar to Large Fibonacci Numbers


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 .

See Also :- C Program To Read Integer (N) And Print First Three Powers (N^1,N^2,N^3)

Solution :-

Method 1 :- Simple Without Using Power Function

#include<bits/stdc++.h>
using namespace std;
int main()
{
/*Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */
  int num;
  cout<<"\nEnter The Number .\n";
  cin>>num;
  cout<<"\nOutpout is \n";
  cout<<num<<"  ,"<<num*num<<"  ,"<<num*num*num<<endl;
  return 0;

}

Method 2 :- Using Power Function

#include<bits/stdc++.h>
using namespace std;
int main()
{
/*Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */
  int num,a,b,c;
  cout<<"\nEnter The Number .\n";
  cin>>num;
  a=pow(num,1);
  b=pow(num,2);
  c=pow(num,3);
  cout<<"\nOutpout is \n";
  cout<<a<<"  ,"<<b<<"  ,"<<c<<endl;
  return 0;
}

See Also :- Java Program To Read Integer (N) And Print First Three Powers (N^1,N^2,N^3)

Output:-


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

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



C++ Program To Calculate Simple Interest
Problem :- Write A Program To Calculate Simple Interest 

Logic :- First take all The input From user like amount ,rate of interest ,and time .after that apply below formula 

Simple Interest :-

SI=amount * Rate * Time / 100 

Solution :-

#include<iostream>
using namespace std;
int main()
{
  long double amt,rate,time,si;

  cout<<"Enter The Principle amount \n";
cin>>amt;

cout<<"\nEnter Rate of Interest \n";
cin>>rate;

cout<<"\nEnter The Time.\n";
cin>>time;
 
  si=(amt*rate*time)/100;
 
cout<<"\nSimple Interest Is = "<<si<<endl;
 
return 0;

}

Output:-

C++ Program To Calculate Simple Interest

C++ Program To Find Area Of Triangle
Problem :- C++ Program To Find Area Of Triangle .

Area Of Triangle:-To Find the Area Of Triangle we need to height and base . given formula show that 

Area = ( Height * Base )/2 


C++ Program To Find Area Of Triangle


See Also :- C Program To Find Area Of Triangle

Solution :-

#include<iostream>
using namespace std;
int main()
{
    /*Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */
    float b,h,area;

    cout<<"Enter Height and Base Of Triangle : ";
    cin>>h>>b;

    area = (h*b)/2;
    cout<<"Area of Triangle is:"<<area<<endl;
    return 0;

}

See Also :- Java Program To Find Area Of Triangle

Output:-

C++ Program To Display Area Of Triangle

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 1 ,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
so follow the next step 

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

See Also :- C Program For Denomination of an Amount

Solution :- 

Method 1 :- Denomination For Indian Rupees

#include<bits/stdc++.h>
using namespace std;
int main() 
{
    /*Program By Ghanendra Yadav
    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; 

  cout<<"Enter The Amount in Rupees : \n\n" ; 
  cin>>amt ; 
 
while(amt >= 2000) 
 
  r2000 = amt / 2000 ; 
  amt = amt % 2000;
  cout<<"\nTotal Number Of 2000 Rupees Notes : "<< r2000 ;
  break ; 
  }
while(amt >= 500) 
 
  r500 = amt / 500 ; 
  amt = amt % 500;
  cout<<"\nTotal Number Of 500 Rupees Notes : "<< r500 ;
  break ; 
 
  while(amt >= 100) 
 
  r100 = amt / 100 ; 
  amt = amt % 100;
  cout<<"\nTotal Number Of 100 Rupees Notes : "<< r100 ;
  break ; 
 
  while(amt >= 50) 
 
  r50 = amt / 50 ;
  amt = amt % 50; 
  cout<<"\nTotal Number Of 50 Rupees Notes : "<< r50 ; 
break ; 
  }  
  while(amt >= 20) 
 
  r20 = amt / 20 ; 
  amt = amt % 20;
  cout<<"\nTotal Number Of 20 Rupees Notes : "<< r20 ; 
  break ; 
  }  
  while(amt >= 10) 
 
  r10 = amt / 10 ; 
  amt = amt % 10;
  cout<<"\nTotal Number Of 10 Rupees Notes Or Coin : "<< r10 ; 
  break ; 
 
  while(amt >= 5) 
 
  r5 = amt / 5 ; 
  amt = amt % 5;
  cout<<"\nTotal Number Of 5 Rupees Notes Or Coin : "<< r5 ; 
  break ; 
 
  while(amt >= 2) 
 
  r2 = amt / 2 ; 
  amt = amt % 2;
  cout<<"\nTotal Number Of 2 Rupees Notes Or Coin : "<< r2 ; 
  break ; 
 
  while(amt >= 1) 
 
  r1 = amt / 1 ; 
  amt = amt % 1;
  cout<<"\nTotal Number Of 1 Rupees Note Or Coin : "<< r1 ; 
  break ; 
  }
count = r2000 + r500 + r100 + r50 + r20 + r10 + r5 + r2 + r1;   
  cout<<"\n\nTotal Number Of Notes Require :"<< count<<endl ; 
return 0;  
}

Method 2 :- Denomination For USA Dollar

#include<bits/stdc++.h>
using namespace std;
int main() 
{
    /*Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */ 
  int amt, r100=0, r50=0, r20=0, r10=0, r5=0, r2=0 , r1=0 ,count=0; 

  cout<<"Enter The Amount in Rupees : \n\n" ; 
  cin>>amt ; 

  while(amt >= 100) 
 
  r100 = amt / 100 ; 
  amt = amt % 100;
  cout<<"\nTotal Number Of 100 Dollar Notes : "<< r100 ;
  break ; 
 
  while(amt >= 50) 
 
  r50 = amt / 50 ;
  amt = amt % 50; 
  cout<<"\nTotal Number Of 50 Dollar Notes : "<< r50 ; 
break ; 
  }  
  while(amt >= 20) 
 
  r20 = amt / 20 ; 
  amt = amt % 20;
  cout<<"\nTotal Number Of 20 Dollar Notes : "<< r20 ; 
  break ; 
  }  
  while(amt >= 10) 
 
  r10 = amt / 10 ; 
  amt = amt % 10;
  cout<<"\nTotal Number Of 10 Dollar Or Coin : "<< r10 ; 
  break ; 
 
  while(amt >= 5) 
 
  r5 = amt / 5 ; 
  amt = amt % 5;
  cout<<"\nTotal Number Of 5 Dollar Or Coin : "<< r5 ; 
  break ; 
 
  while(amt >= 2) 
 
  r2 = amt / 2 ; 
  amt = amt % 2;
  cout<<"\nTotal Number Of 2 Dollar Or Coin : "<< r2 ; 
  break ; 
 
  while(amt >= 1) 
 
  r1 = amt / 1 ; 
  amt = amt % 1;
  cout<<"\nTotal Number Of 1 Dollar Or Coin : "<< r1 ; 
  break ; 
  }
count = r100 + r50 + r20 + r10 + r5 + r2 + r1;   
  cout<<"\n\nTotal Number Of Dollar Require :"<< count<<endl ; 
return 0;  

}

See Also :- Java Program For Denomination of an Amount

Output:-


C++ Program For Denomination of an Amount

C++ Program For Denomination For USA Dollar