Thursday 20 December 2012

how to make pyramid in c++

construct pyramid of x in c++
how to make pyramid in c++

construct pyramid of x in c++:- 

This is the source code to make pyramid from asterik using c++.....

#include<iostream>
#include<iomanip>
using namespace std;
main(){
       int u=1;
       int space;
       int i,x;
       cout<<"Enter the length of the pyramid:";
       cin>>x;
       while(u<=x)
       {
                  i=1;
                  cout<<setw(space);
                  while(i++<=u)
                  cout<<"X";
                  u=u+2;
                  space--;
                  cout<<endl;
                  }
       system("pause");          
       }
End

 And:
pyramid in c++
how to make pyramid in c++

how to find that the given number is a palindrome


This is the source code to find that the given number is palindrome or not........

#include<iostream.h>
#include<conio.h>
main()
{
      int number,a,b,c,d,e,f,g,h,mango;
      cout<<"Ente the five digit number:";
      cin>>number;
      cout<<endl;
      mango=number/10000;
      a=number%10000;
      b=a/1000;
      c=a%1000;
      d=c/100;
      e=c%100;
      f=e/10;
      g=e%10;
      cout<<mango<<b<<d<<f<<g<<endl;
      if(mango==g && b==f)
      cout<<"number is palindrom";
      else
      cout<<"number is not a palindrom";
      getch();
}
End
     

Tuesday 16 October 2012

how to find larger number using c++


This is source code to find the larger number from given numbers

#include<iostream.h>
#include<conio.h>
main()
{
      int num;
      int larger=0;
      for(int i=1;i<=10;i++){
            cout<<"Enter number"<<i<<":"<<endl;
            cin>>num;
               if(num>larger){
                             larger=num;
                              }
                              }
                              cout<<"larger num is="<<larger<<endl;
                              getch();
}                             
End

Saturday 13 October 2012

how to find the prime number using c++(with simple coding)


how to find prime number in c++
how to find prime number in c++:
This is the source code for determining that given number is prime or not
#include<iostream.h>
#include<conio.h>
main()
{
      int x;
      for(int i=1;i<=100;i++){
      cout<<"enter the number"<<endl;
      cin>>x;
      if(x==2 || x==3 || x==5){
             cout<<"number is prime"<<endl;
             }
      else if(x%2==0 || x%3==0 || x%5==0)
      {
                cout<<"not prime"<<endl;
                }
                else
                {
                    cout<<"number is prime"<<endl;
                    }
                     
                       }
                    getch();
                    }
End

Friday 27 July 2012

how to find prime number using c++


 This is the source code for finding prime number 
#include<iostream.h>
#include<conio.h>
main()
{
      int n,d,p=1;
      cout<<"enter the number?";
      cin>>n;
      d=2;
      while(d<=n/2)
      {
                   if(n%d==0)
                   p=0;
                   d++;
                   }
                   if(p==0)
                   cout<<"not prime number";
                   else
                   cout<<"prime number";
                   getch();
                   }
      End

Wednesday 25 July 2012

how to fill and display array using functions

This is the source code of how to fill and display array using functions
                                               
#include<iostream.h>
#include<conio.h>

const int n=9;
int GA[n];


void fillarray(void){
    const int n=9;
    int A[n];
   
    int i=0;
    while(i<=9){
       
        cout<<"value of element"<<i<<"?"<<endl;
        cin>>A[i];
       
        GA[i]=A[i];
        i++;
       
   
    }
   

}


void displayarray(void){

  for(int i=0;i<=9;i++){
     cout<<GA[i]<<endl;
      }   
  }
 



int main()
{
    fillarray();
    displayarray();
    getch();
   
}
End

Sunday 8 July 2012

how to fill the array of five elements



This is the source code to fill the array of five elements

Code: #include<iostream.h>
#include<conio.h>
main()
{
     int A[5];
     int r;
     for(r=0;r<5;r++)
     {
                     cout<<"enter the value";
                     cin>>A[r];
                     }
      getch();
      }

How to calculate the average of all the values in the array



This is the source code to calculate the average of all the values in the array
#include<iostream.h>
#include<conio.h>
main()
{
      int A[5]={3,6,9,12,15};
      int sum;
      float average;
      sum=A[0]+A[1]+A[2]+A[3]+A[4];
      average=sum/5;
      cout<<"Average="<<average<<endl;
      getch();
      }
End

How to calculate the sum of all values in an array



This is the source code to calculate the sum of all the values in an array
#include<iostream.h>
#include<conio.h>
main()
{
      int A[5]={3,6,9,12,15};
      int sum;
      sum=A[0]+A[1]+A[2]+A[3]+A[4];
      cout<<"sum="<<sum<<endl;
      getch();
      }
End

Saturday 30 June 2012

simple program of c++ to understand the use array



This is the source code for understand the simple function of array.
Here we have to calculate the average temperature of 7 days using array in c++.
#include<iostream.h>
#include<conio.h>
main()
{
      float temp[7],sum=0;
      int i=0;
      while(i<=6)
      {
                 cout<<"enter the temp. of day"<<i+1<<"?"<<endl;
                 cin>>temp[i];
                sum=sum+temp[i];
                i++;
                }
                cout<<"\nAverage temperature :"<<sum/7.0;
             
                getch();
                }
End

Sunday 24 June 2012

how to display data type size using c++



sizeof cplusplus

A program to display the data type size.
//By using predefined sizeof() function,
//,, 1 byte = 8 bits
#include <iostream.h>
#include <stdlib.h>
int main()
{
cout<<"The size of an int is:\t\t"<<sizeof(int)<<" bytes.\n";
cout<<"The size of a short int is:\t"<<sizeof(short)<<" bytes.\n";
cout<<"The size of a long int is:\t"<<sizeof(long)<<" bytes.\n";
cout<<"The size of a char is:\t\t"<<sizeof(char)<<" bytes.\n";
cout<<"The size of a float is:\t\t"<<sizeof(float)<<" bytes.\n";
cout<<"The size of a double is:\t"<<sizeof(double)<<" bytes.\n";
cout<<"The size of a bool is:\t\t"<<sizeof(bool)<<" bytes.\n";
system("pause");
return 0;
}
End

sizeof cplusplus

what is data type in c++



Fundamental data types
When programming, we store the variables in our computer's memory, but the computer has to know what kind of data we want to store in them, since it is not going to occupy the same amount of memory to store a simple number than to store a single letter or a large number, and they are not going to be interpreted the same way.

The memory in our computers is organized in bytes. A byte is the minimum amount of memory that we can manage in C++. A byte can store a relatively small amount of data: one single character or a small integer (generally an integer between 0 and 255). In addition, the computer can manipulate more complex data types that come from grouping several bytes, such as long numbers or non-integer numbers.
What is a data type?
When we wish to store data in a C++ program, such as a whole number or a character, we have to tell the compiler which type of data we want to store. The data type will have characteristics such as the range of values that can be stored and the operations that can be performed on variables of that type


Next you have a summary of the basic fundamental data types in C++, as well as the range of values that can be represented with each one:


Name
Description
Size*
Range*
char
Character or small integer.
1byte
signed: -128 to 127
unsigned: 0 to 255
short int(short)
Short Integer.
2bytes
signed: -32768 to 32767
unsigned: 0 to 65535
int
Integer.
4bytes
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int (long)
Long integer.
4bytes
signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool
Boolean value. It can take one of two values: true or false.
1byte
true or false
float
Floating point number.
4bytes
+/- 3.4e +/- 38 (~7 digits)
double
Double precision floating point number.
8bytes
+/- 1.7e +/- 308 (~15 digits)
long double
Long double precision floating point number.
8bytes
+/- 1.7e +/- 308 (~15 digits)
wchar_t
Wide character.
2 or 4 bytes
1 wide character