07/03/2015

C Program To Find A Percentage Of Marks
Problem :- Write A C Program To Find A Percentage Of Marks .

Logic :- First We take input marks Of All 6 Subject from User ,then we add all subject and after that divide by number or subject 

Formula :- 

Percentage = Sum of all Subject / Number of Subject 

Solution :-

#include<stdio.h>
main()
{
int ph,ch,math,eng,sc,sci;
float per;

printf("Enter The Marks Of Subject ph,ch,math,eng,sc,sci\n");
scanf("%d%d%d%d%d%d" ,&ph,&ch,&math,&eng,&sc,&sci);

per=(ph+ch+math+eng+sc+sci)/6;

printf("\nPercentage = %f\n",per);


}

Output:-

C Program To Find A Percentage Of Marks

C++ Program To Find Triangle Is Equilateral Isosceles Right angled Or Scalene
Write A C++ Program To Find Triangle Is Equilateral, Isosceles, Right angled Or Scalene. Before writing the code we must know what is Equilateral or what is Isosceles, what is Right angled what is Scalene Triangle. As we all know that triangles have 3 sides. So based on the sides we can identify the type of triangle.

c++ program to check whether the triangle is an equilateral, isosceles or scalene triangle using if else statement

Type of Triangles 


Below are the 4 types of triangles. 

1. Equilateral Triangle


An equilateral triangle is a triangle in which all three sides have the same length. In the familiar Euclidean geometry, an equilateral triangle is also equiangular; that is, all three internal angles are also congruent to each other and are each 60°.

Equilateral Triangle

If all the side (A, B, C) of the Triangle is equal means if A = B = C then the triangle is Equilateral Triangle.

2. Isosceles Triangle


An isosceles triangle is a triangle that has two sides of equal length. Sometimes it is specified as having exactly two sides of equal length, and sometimes as having at least two sides of equal length, the latter version thus including the equilateral triangle as a special case.

Isosceles Triangle

If two sides of a Triangle Is Equal In length means if A = B or B = C or C = A then the triangle is Isosceles Triangle.

3. Right-Angled Triangle


Right-angled triangles are those triangles in which one angle is 90 degrees. Since one angle is 90°, the sum of the other two angles will be 90°.

Right Angled Triangle

To be a right angle means a*a == b*b + c*c or b*b == c*c + a*a or c*c == a*a + b*b any one of the Conditions is true then it is Right angled Triangle.

4. Scalene Triangle


A scalene triangle can be defined as a triangle whose all three sides have different lengths, and all three angles are of different measures. The angles of a scalene triangle follow the angle sum property and always add up to 180.

Scalene Triangle

If all Sides are Unequal Then It is Scalene Triangle.

C++ Program to Check Triangle Is Right-Angled, Equilateral, Isosceles or Scalene


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

/* Enter all side's Triangle*/
 cout<<"Enter The Value of a, b, c \n";
 cin>>a>>b>>c;

 if(a==b && b==c && c==a)
 {
  cout<<"The Triangle is Equilateral Triangle\n");
 }
 else if(a==b || b==c || c==a)
 {
  cout<<"The Triangle is Isosceles Triangle\n");
 }
 else if(a*a==b*b+c*c ||b*b==c*c+a*a || c*c==a*a+b*b)
 {
  cout<<"The Triangle is Right Triangle\n");
 }
 else
 {
  cout<<"The Triangle Scalene Triangle\n");
 }
 return 0;

}

Triangle Is Equilateral Isosceles Right angled Or Scalene Program Output in C++


Write C++ Program to Check Whether a Triangle Is Right-Angled, Equilateral, Isosceles or Scalene
C++ Program To Print A Message Multiple Times
Problem :- Write A Program To Print A Message Multiple Times

Logic :- Enter your MSG and Run any loop ,this is your choice how many time's you want to print a MSG 

Solution :-

#include<iostream>
using namespace std;
int main()
{
  int n,i;
  string str;
 
cout<<"Enter The MSG :\n";
cin>>str;
 
cout<<"Enter How Many Times You Want To Print MSG : \n";
cin>>n;
 
for(i=0 ;i<n ;i++)
{
cout<<str<<endl;
}
cout<<endl;
 return 0;

}

Output:-

C++ Program To Print A Message Multiple Times

03/03/2015

C++ Program To Check Upper Case Lower Case Digit And Special Symbol
Problem :- Write A Program To Check Upper case Lower case Digit And Special Symbol .

Logic :- This is a simple logic we check all the thing with ASCII value or Character we put condition like if character ASCII value is between 97 to 122 then character is lower case or if 65 to 90 then Upper case or if ASCII value is between 48 to 57 then it is Digit .
if above all condition is not true then it is a Special Symbol .

Solution :-

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

cout<<"Press Any Key....\n"<<endl;
cin>>a;

if(a>=65 && a<90)
{
cout<<"Key Is Upper Key\n"<<endl;
}

else
{
  if(a>=97 && a<=122)
  {
  cout<<"Key Is Lower Key\n"<<endl;
}
  else
  {
  if(a>=48 && a<=57)
  {
  cout<<"Key Is Degit\n"<<endl;
}
  else
  {
  cout<<"Key Is Special Symbol\n"<<endl;
}
  }
}
return 0;

}

Output :-

C++ Program To Check Upper Case Lower Case Digit And Special Symbol

C++ Program To Print Table Of Any Given Number
Problem :- Write A Program To Find Table Of Any Given Number Entered By User

Logic :- Take a input from user then use an any loop and start with condition =1;condition <=10; and increase by one each time ,and multiply input with condition and print .

Solution :-

Method 1:- 

#include<iostream>
using namespace std;

int main()
{
    int i,a,num;
    cout<<"Enter The Number That You Want To Print Table \n";
    cin>>num;

    for(i=1;i<=10;i++)
    {
        a=num*i;
        cout<<num<<" * "<<i<<" = "<<a<<endl;
    }

    return 0;

}

Method 2:- Here is An Another Way to Find Any  Table

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

Output:-

C++ Program To Print Table Of Any Given Number

C++ Program To Find Number Is Prime Or Not
Problem :- Write A Program To Find Number Is Prime Or Not

Prime Number :- A Number That Can Only Divisible By Itself or 1.
You can see that it's clear a number divisible by itself or one then use a loop start from one like condition=1 and max condition up to <=Number 
and divide a number by condition and increase counter by ++ if number divide after the end if count is equal to 2 then number is prime otherwise not.

Solution :-

#include<iostream>
using namespace std;
int main()
{
    int number,count=0;
    
cout<<"ENTER NUMBER TO CHECK IT IS PRIME OR NOT ";
    cin>>number;
    
for(int a=1;a<=number;a++)
    {
        if(number%a==0)
        {
            count++;
        }
    }
    if(count==2)
    {
        cout<<"\n"<<number<<"IS PRIME NUMBER \n";
    }
    else
    {
        cout<<"\n"<<number<<"IS NOT A PRIME NUMBER \n";
    }
    return 0;

}

Output:-

C++ Program To Find Number Is Prime Or Not

C++Program To Swap A Number Without Using Third Variable
Problem :- Write A Program To Swap A Number Without Using Third Variable

Logic :- Swapping A two Number without Using Third Variable Is A simple logic that i am Explaining below .

Example :- a=10 And b=20 .

Step 1:- first add both number like a=a+b so a value is 30.

Step 2:- Now sub-struct b=a-b so b value is 10.

Step 3:- Finally a=a-b so 30-10=20 so a value is 20.

finally Number is swap .

Solution :-

#include <iostream>
using namespace std;

int main()
{
    int first,second;
    
cout<<"Enter The First And Second Variable :\n\n";
    cin>>first>>second;
    
first=first+second;
    second=first-second;
    first=first-second;
    
cout<<"\nFirst Number is = "<<first<<"\nSecond Number Is = "<<second<<endl;
    return 0;

}

Output:-

C++Program To Swap A Number Without Using Third Variable

C++ Program To Check Even Or Odd Using Pointer
Problem:- Write A Program To Find A Number Is Even Or Odd Using a Pointer or a c++ program to find even and odd numbers using the function or a c++ program to find odd or even using a class or a c++ program to find even and odd numbers using an array or c program to print even numbers in an array or even odd program in c++ using an array or c++ odd or even loop or c++ program to check whether a number is even or odd using a function or c program to check whether a number is prime or not using the function or c program for even or odd using for loop

Logic:- As we know that if the number is less than zero then a number is Negative or if a Number is Greater than Zero then the number is Positive or in any case number is equal to zero. So in this problem we are comparing if the entered number by the user is less than zero or greater than zero or if both conditions fail then a number is definitely zero or we can say entered a number is zero.


Extreme Recommended:- If you have any queries you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.



Solution:-

#include<iostream>
using namespace std;
int main()
{
  int a;
  int *p1;
 
  p1=&a;
 
  cout<<"Enter The Number You Want to Check \n\n";
  cin>>a;
 
if(*p1>0)
  {
  cout<<"Number Is Possitive \n";
}
  else if(*p1<0)
  {
  cout<<"Number Is Negative \n";
}
  else
  {
  cout<<"Number Is Equal to Zero\n\n";
}
  return 0;

}

Output:-

C++ Program To Check Even Or Odd Using Pointer

You May Also Like


  1. Program to Display the Size of the Different Datatype
  2. Write a C Program Check Number Is Positive or Negative
  3. Find the Character Is Vowel or Not
  4. Calculate the Factorial of a Given Number
  5. Read Integer N and Print the First Three Powers (N^1, N^2, N^3)

02/03/2015

C++ program to print ASCII value of a character
Problem:- Write A Program To Find ASCII Value Of Any Character or C++ program to print ASCII value of a character or C program to print ASCII value of a character

ASCII:- Abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Most modern character-encoding schemes are based on ASCII, although they support many additional characters. 

ASCII-code order is also called ASCIIbetical order.The main deviations in ASCII order are:

1. All upper case come before lowercase letters; for example, "Z" precedes "a".

2. Digits and many punctuation marks come before letters.

ASCII Value Chart Is Below 

ASCII Value Chart

source-Wikipedia

Logic:- As we know that  every key in keyboard has a unique ASCII key, so for as you enter or press any key on keyboard we take string and convert string into integer value, or we can also take a string and print the string ASCII value using loop as you see in the below program. In this program, i am taking a character or string and by using loop convert the string into integer, actually string in not converting it just printing an integer value of that character and the loop is running until our string not finished that's why we use '\0' means end of string or we can say that last character in string.

Example:-

 for(i=0; str[i]!='\0'; i++)
 {
 ch=str[i];
 cout<<(int)ch<<" ";
 }

as you can see that each character of the string array is storing in character and print the character ASCII value.

Explanation:-  ASCII Full Form " American Standard Code for Information Interchange ". Every Character of your Keyboard Have It's Own Unique Number Like 

ASCII value for small character ' a ' to ' z ' is ' 97 ' to ' 122 '.
ASCII value for capital character ' A ' to ' Z ' is ' 65 ' to ' 90 '.
ASCII value for number ' 0 ' to ' 1 ' is ' 48 ' to ' 57 '  etc.

Solution:-

#include<bits/stdc++.h>
using namespace std;
int main()
{
 string str;
 int i;
 char ch;

 cout<<"Enter String Or Character For ASCII Value \n";
 cin>>str;

 cout<<"\nString Is Given Below\n";
 cout<<str; 

 cout<<"\n\nASCII Value Of Given String Or Character Is Below\n\n";

 for(i=0; str[i]!='\0'; i++)
 {
 ch=str[i];
 cout<<(int)ch<<" ";
 }

 cout<<endl;
  return 0;

}

Output:-

C++ program to print ASCII value of a character


You May Like This:-

1. C++ Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol

2. Java Program To Find Area Of Triangle

3. C++ Program For Calculate Simple Interest

4. C++ Program For Find The Gross Salary Of An Employee

5. C++ Program For Calculate Percentage Of 5 Subjects

6. Java Program For Converting Temperature Celsius Into Fahrenheit

7. C Program To Find Character Is Vowel Or Not

8. Hacker Rank Solution Program In C++ For " StringStream "

9. Hacker Rank Solution Program In C++ For " Attribute Parser "

10. Geeksforgeeks Solution For " Reverse Coding "


C++ Program To Find Factorial
Problem:- Write A C++ Program To Calculate Factorial Of A Given Number or factorial program in c or Factorial For Large Number Using Array.

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!. This fact was known at least as early as the 12th century, to Indian scholars.
Source:- Wikipedia

Logic:- Suppose we want to find factorial of number 6 then we can multiply number from 1 to 6 (n) like 1 * 2 * 3 * 4 * 5 * 6 = 720. So we can use a loop and run the loop from 1 to number n (the number whose factorial you want) and multiply a number, this is a simple way to find a factorial. You can also find the factorial program for Large Number.

Factorial Use's in Real Life:-

1. Trigonometry,
2. The exponential function
3. Permutations and Combinations
4. Calculus (Like Taylor’s Series and Maclaurin Series) 
5. Data Distributions

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

Solution:-

Method 1:- Factorial Using For Loop

#include<iostream>
using namespace std;

int main()
{
 /*Program By Ghanendra Yadav
    Visit http://www.programmingwithbasics.com/
    */
  
 unsigned long long int fact=1;
  int i,num;
  
 cout<<"Enter The Number. You Want Factorial:";
  cin>>num;
  
 for(i=1;i<=num;i++)
    {
        fact=fact*i;
    }
    
 cout<<"\nFactorial of "<<num<<" Is = "<<fact<<endl;
    return 0;

}

Method 2:-  Factorial For Large Number Using Array


#include <cstring>
#include <iostream>
#include <cstdlib>
#define ll long long
using namespace std;
int fact[10001][10000] = {0};
void fact_large(int n)
{
    int i;
    fact[1][0] = 1;
    fact[1][1] = 1;
    if (fact[n][0] == 0) 
    {
        for (i = n - 1; i > 0 ; i--) 
        {
            if (fact[i][0] != 0)
                break;
        }
        for ( ; i < n; i++) 
        {
            int j = 1;
            int carry = 0;
            int len = fact[i][0];
            while (len--)
            {
                int temp = (i + 1) * fact[i][j] + carry;
                fact[i + 1][j] = temp % 10;
                carry = temp / 10;
                j++;
            }
            while (carry > 0) 
            {
                fact[i + 1][j] = carry % 10;
                carry /= 10;
                j++;
            }
            fact[i + 1][0] = j - 1;
        }
    }
    for (i = fact[n][0]; i > 0; i--) 
    {
        cout << fact[n][i];
    }
    cout<<endl;
}

int main()
{
    int n,t;
     cout<<"Enter The Number \n";
        cin>>n;
        fact_large(n);
    return 0;
}

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

Output:-

1. Factorial Using For Loop

C++ Program To Find Factorial


2. Factorial For Large Number Using Array

C++ Program To Find Factorial

You May Also Like:-











C++ Program To Find Compound Interest
Problem:- C++ Program To Find Compound Interest or compound interest program in c or c program for compound interest.

Logic:- According to Wikipedia Compound interest is the addition of interest to the principal sum of a loan or deposit, or in other words, interest on interest. It is the result of reinvesting interest, rather than paying it out, so that interest in the next period is then earned on the principal sum plus previously-accumulated interest. Compound interest is standard in finance and economics.

Compound interest may be contrasted with simple interest, where interest is not added to the principal, so there is no compounding. The simple annual interest rate is the interest amount per period, multiplied by the number of periods per year. The simple annual interest rate is also known as the nominal interest rate.

Compound Interest Formula:-

CI = ( P * (pow((1+r/n),(n*t))) - P);

Where  

P = Principal amount .
r = Rate of nterest ( Annual ).
n = compounding frequency ( Monthly ).
t = time

Example:- We have 10,000 Rs is invested for in company rate of interest is 5%, and compounded monthly and for 15 years what will be the profit in principal amount, Explain with a step by step.

Explanation:-

r = R / 100.

P = 10,000.
r = 5/100 = 0.05.
n = 12.
t = 15.

Now put these value in formula and after calculation remove the principal amount from compound interest so we can get total Compound Interest.

CI = ( 10,000 * (1 + 0.05 / 12 ) ^  ( 12 * 15 ) - 10,000 ).

So here we get final Compound interest earn is = 11137.2 Rs.

Solution:-

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
 //By-Ghanendra Yadav

 float P, r, t, n, R, CI;
  
 cout<<"\n\nEnter The Principal Amount :\n";
 cin>>P;

 cout<<"\n\nEnter Rate of Interest (Annual) :\n";
 cin>>R;

 cout<<"\n\nEnter compounding frequency (Monthly) :\n";
 cin>>n;

 cout<<"\n\nEnter Time (Period) :\n";
 cin>>t;

 r = R / 100;

 CI = ( P * (pow((1+r/n),(n*t))) - P);

 cout<<"\n\nCompound Interest is After "<<t<<" Years is = "<<CI<<endl<<endl;

 return 0;

}

Output:-

compound interest program in c

You May Like This:-










C++ Program To Check Number Is Positive Or Negative
Problem:- Write A C++ Program To Check Number Is Positive Or Negative. The number should be Entered Through the User Then the program Prints the Output.

Logic:- As we know that if a number is greater than 0 ( Zero ) Then the number is positive and if a number is Less than 0 ( Zero ) then the number is Negative and if else number is equal to zero then an entered number is Zero or equal to zero. Below is an explanation of the problem with an example. For this type of problem,  there may be a maximum of 3 cases, all cases are given below.

Case 1:- Either number is greater than zero (Number is Positive).
Case 2:- Either number is less than zero (Number is Negative).
Case 3:- or number is equal to zero (Number is Equal to Zero).

Example:- 

Case 1:- If a number is greater than zero the number is positive let's take an example to assume the number is 20 then compare the number 20 to zero definitely number is greater than zero so the program will print "Entered number is the Positive number".

int a;  // 'a' is a number entered by the user.
if(a>0)
 {
   cout<<"Number Is Positive:\n";
 } 

Case 2:- If a number is less than zero the number is negative let's take an example to assume the number is -20 then compare the number -20 to zero definitely number is less than zero so the program will print "Entered number is the Negative number".

int a;  // 'a' is a number entered by the user.
if(a<0)
 {
   cout<<"Number Is Negative:\n";
 } 

Case 3:- If a number is equal to zero the number is Zero let's take an example to assume the number is 0 (Zero) and then compare the number 0 (Zero) to Zero definitely number is equal to zero so the program will print "Entered number is Zero".

int a;  // 'a' is a number entered by the user.
if(a==0)
 {
   cout<<"Entered Number Is Zero:\n";
 } 

See Also:- C Program To Check Number Is Positive Or Negative

Solution:- 

#include<iostream>
using namespace std;
int main()
{
 int a;
 cout<<"Enter The Number You Want To Check: \n";
 cin>>a;

 if(a<0)
 {
   cout<<"Number Is Negative:\n";
 }
 else if(a>0)
 {
   cout<<"Number Is Possitive:\n";
 } 
 else
 {
  cout<<"You Enter Zero :\n";
  }
 return 0;

}

See Also:- Java Program to Find Number Is Positive or Negative

Output:-

C++ Program To Check Number Is Positive Or Negative

You May Also Like:-





C++ Program For Addition, Subtraction, Multiply, Divide And Average
Problem:- C++ Program To Find Addition, Subtraction, Multiply, Divide And Average.

Logic:- For this type of question, we all know that addition, subtraction, multiply, divide, and average. For addition, we use a plus(+) operator, for subtraction we use minus(-) operator, for multiple we use an asterisk(*), for divide or division we use, the division operator or asterisk(*) and for average first, we add all number then divide the total sum by counting number.

1. Addition:-

Sum = number X + number Y......................number n.

for addition at-least, 2 number required means if you want a sum than two number required. Example 5+15=20, here we know that in the programming language we need to store a number in variables so we should initialize some variable.
Explanation: 
int number1,number2.
int sum_of_number1_and_number2. 
so first number 5 stored in number1, and 15 stored in number2. Now, what is a use of sum_of_number1_and_number2 ?.
5 and 15 are already stored in number1 and number2 than for storing the sum value of 5+15 we initialize third variable sum_of_number1_and_number2.

sum_of_number1_and_number2 = number1 + number2;

sum_of_number1_and_number2 = 5 + 15;

Values of sum_of_number1_and_number2 = 20;
and in the last, we print the sum value. I hope now I am clear about variables and logic.
same process repeat for subtraction, multiply and divide. But for average there is little bit change

2. Average:-

For average process is similar but here you need to count a number. cause after adding you need to divide a number. For that, you can either use the third variable or you can do this by using the same variable.
Explanation:
sum_of_number1_and_number2 = number1 + number2;
now we know that there is two number then in the last we divide a sum_of_number1_and_number2 by two.
Average = sum_of_number1_and_number2 / 2;
Average = 20 / 2;
Average = 10;

Solution:-

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

cout<<"enter the two number :"<<endl;
cin>>a>>b;                              

c=a+b;

cout<<"sum is = "<<c<<endl;

cout<<"enter the two nuber :"<<endl;
cin>>a>>b;                                           

c=a-b;

cout<<"sub is = "<<c<<endl;

cout<<"enter the two nuber :"<<endl;
cin>>a>>b;

c=a*b;

cout<<"mul is = "<<c<<endl; 

cout<<"enter the two nuber :"<<endl;
cin>>a>>b;

c=a/b;

cout<<"dev is = "<<c<<endl; 

cout<<"enter the two nuber :"<<endl;
cin>>a>>b;

c=a%b;

cout<<"modulus is = "<<c<<endl; 

cout<<"enter the two nuber :"<<endl;
cin>>a>>b;

c=(a+b)/2;  

cout<<"avg is = "<<c<<endl; 
return 0;
}

Output:-



C++ Program To Find Addition, Subtraction, Multiply, Divide And Average