Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Monday, 22 April 2013

A programe to calculate factorial of a number

Description:

This program take a number from user as input and find its factorial automatically.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
#include<math.h>
using namespace std;
int main()
{
       float a,b=1,c,i,f;
    cout<<"A programe to calculate factorial of a number"<<endl;
    xy:
    cout<<"Enter a number to calculate its factorial"<<endl;
    cin>>a;
    cout<<endl;
    i=a;
    while(i>=1)
    {
      b=b*i;
      i--;
      }
      cout<<"The factorial of the given number is"<<b<<endl;
      goto xy;
      getche();
      return 0;
      }


Output:


A programme to check the divisibility of a number by 3

Description:

In C++ if there is conditional logic then "if", "else" statements are used.

Code:


#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int main()
{
    int a,b,c;
    cout<<"A programe to check the divisibility of a number by 3"<<endl;
    xy:
    cout<<"Enter the number to check its divisibility"<<endl;
    cin>>a;
    cout<<endl;
    if(a%3==0)
    {
              cout<<"The number is divisible by 3"<<endl;
           
              }
           
              goto xy;
              getche();
              return 0;
              }


Output: