Showing posts with label Display. Show all posts
Showing posts with label Display. Show all posts

C++ Program to display the sum of this series: 1+1/2+1/3....1/n.

C++ Program to display the sum of this series: 1+1/2+1/3....1/n.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a,b=0,i;
cout<<"Enter a number: ";
cin>>a;
for(i=1;i<=a;i++)
b=b+(1/i);
cout<<"The sum of the series is: "<<b;
getch();
}

C++ Program to enter an amount and display no. of Rs.500,100,50,20,10,5,1 notes.

C++ Program to enter an amount and display no. of Rs.500,100,50,20,10,5,1 notes.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int long a;
cout<<"Enter amount: ";
cin>>a;
cout<<"No. of Rs. 500 notes: "<<a/500<<endl;
a=a%500;
cout<<"No. of Rs. 100 notes: "<<a/100<<endl;
a=a%100;
cout<<"No. of Rs. 50 notes: "<<a/50<<endl;
a=a%50;
cout<<"No. of Rs. 20 notes: "<<a/20<<endl;
a=a%20;
cout<<"No. of Rs. 10 notes: "<<a/10<<endl;
a=a%10;
cout<<"No. of Rs. 5 notes: "<<a/5<<endl;
a=a%5;
cout<<"No. of Re. 1 notes: "<<a/1;
getch();
}

C++ Program to enter 'n' numbers and display no. of odd, even and numbers entered till user wishes.

C++ Program to enter 'n' numbers and display no. of odd, even and numbers entered till user wishes.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a=0,b,o=0,e=0;
char z;
do
{
++a;
cout<<"Enter a number: ";
cin>>b;
if(b%2==0)
++e;
else
++o;
cout<<"Enter another number? (y/n): ";
cin>>z;
}
while(z=='y'||z=='Y');
cout<<"Number of number entered: "<<a<<endl;
cout<<"Number of even numbers: "<<e<<endl;
cout<<"Number of odd numbers: "<<o<<endl;
getch();
}

C++ Program to display prime numbers upto n.

C++ Program to display prime numbers upto n.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c,z;
cout<<"Enter a number: ";
cin>>a;
cout<<"The prime numbers upto "<<a<<" are: "<<endl;
for(b=2;b<=a;b++)
{
z=0;
for(c=1;c<=b;c++)
{
if(b%c==0)
z++;
}
if(z==2)
cout<<b<<" ";
}
getch();
}

C++ Program to display first n terms of fibonacci series.

C++ Program to display first n terms of fibonacci series.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
long a,b=0,c=1,d=1;
cout<<"Enter the number of terms of fibnoacci series to display: ";
cin>>a;
cout<<"The first "<<a<<" terms of fibonacci series are: "<<endl;
for(int i=0;i<=a;i++)
{
d=b+c;
b=c;
c=d;
cout<<d<<" ";
}
getch();
}

C++ Program to display a number's digits reversed.

C++ Program to display a number's digits reversed.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a;
cout<<"Enter a number to display it's digits reversed: ";
cin>>a;
a=(a%10)*(10)+(a/10);
cout<<"The reversed number is: "<<a;
getch();
}

C++ Program to display the sum of a number's digits.

C++ Program to display the sum of a number's digits.



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b,c;
cout<<"Enter a number to display sum of it's digits: ";
cin>>a;
b=a%10;
while(a!=0)
{
a=a/10;
c=a%10;
b=b+c;
}
cout<<"The sum of the digits is: "<<b;
getch();
}

Program to display the following pattern: 1 12 123 1234 12345

Write a C++ Program to Display the Following Pattern.


/* Program to display the following pattern:
1
12
123
1234
12345
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
cout<<j;
cout<<endl;
}
getch();
}

Program to display the following pattern: * ** *** **** *****

Write a C++ Program to Display the Following Pattern.



/* Program to display the following pattern:
    *
   **
  ***
 ****
*****
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<=5;i++)
{
for(int j=4;j>=i;j--)
cout<<" ";
for(int k=1;k<=i;k++)
cout<<"*";
cout<<endl;
}
getch();
}

Program to display the following pattern: ********** ********** **********

Write a C++ Program to Display the Following Pattern.



/* Program to display the following pattern:
**********
**********
**********
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<=3;i++)
{
for(int j=1;j<=10;j++)
cout<<"*";
cout<<endl;
}
getch();
}

Program to display the following pattern: * *** ***** ******* *********

Write a C++ Program to Display the Following Pattern.



/* Program to display the following pattern:
    *
   ***
  *****
 *******
*********
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1,l=4;i<=9;i+=2,l--)
{
for(int j=1;j<=l;j++)
cout<<" ";
for(int k=1;k<=i;k++)
cout<<"*";
cout<<endl;
}
getch();
}

Program to display the following pattern: 1 222 33333 4444444 555555555

Write a C++ Program to Display the Following Pattern.



/* Program to display the following pattern:
    1
   222
  33333
 4444444
555555555
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1,l=4,m=1;i<=9;i+=2,l--,m++)
{
for(int j=1;j<=l;j++)
cout<<" ";
for(int k=1;k<=i;k++)
cout<<m;
cout<<endl;
}
getch();
}

Read Content From a Text File then Count and Display the Number of Alphabets

How to write a C++ Program to read content from a text file out.txt, count and display the number of alphabets present in it in C++ Programming.


C++ Program to read content from a text file out.txt, count and display the number of alphabets present in it
C++ Program to read content from a text file out.txt, count and display the number of alphabets present in it 


Soulution:
//Program to read content from a text file out.txt, count and display the number of alphabets present in it.
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
void main()
{
clrscr();

char a;
int count=0;
ifstream ifile("out.txt");
while(!ifile.eof())
{
ifile.get(a);
if((a>=65 && a<=90)||(a>=97&&a<=122))
{
count++;
cout<<a;
}
}
cout<<endl<<"Number of aplhabets in the file out.txt: "<<count;
getch();
}

This C++ Program to read content from a text file out.txt, count and display the number of alphabets present in it in C++ Programming.

Program to display Pyramid in C++

How to Program to display Pyramid in C++ Programming ?


Program to display the following pattern: Pyramid and Pattern pyramid pattern program in c pyramid pattern programs in java pyramid pattern program in php pyramid pattern of numbers in java pyramid pattern in javascript pyramid pattern in python pyramid pattern in c language

Program to display Pyramid in C++

Solution:
/*
Program to display the following pattern:
    1
   212
  32123
 4321234
543212345
*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
for(int i=1;i<=5;i++)
{
for(int j=4;j>=i;j--)
cout<<" ";
for(int k=i;k>=1;k--)
cout<<k;
for(int l=2;l<=i;l++)
cout<<l;
cout<<endl;
}
getch();
}

This Program to display Pyramid in C++.

C++ Program to display factorial of a number.

How to display factorial of a number in C++ programming ?

C++ Program to display factorial of a number.Program to find factorial of Number in C++ c++ program to find factorial of a number c++ program to find factorial of a number using class c++ program to find factorial of a number using function c++ program to find factorial of a number using constructor c++ program to find factorial of a number using inline function c++ program to find factorial of a number using recursion c++ program to find factorial of a number using while loop write a c++ program to find the factorial of a number
C++ Program to display factorial of a number.

Solution:
//Program to display factorial of a number.
#include<iostream.h>
#include<conio.h>
fac(int);
void main()
{
clrscr();
int a;
char z;
do
{
cout<<"Enter a number: ";
cin>>a;
a=fac(a);
cout<<"The factorial is: "<<a<<endl;
cout<<"Do you wish to display another factorial? (y/n): ";
cin>>z;
}
while(z=='y'||z=='Y');
}

fac(int a)
{
int i,b;
for(i=1,b=1;i<=a;i++)
b=b*i;
return b;
}

This C++ Program display factorial of a number.