The document contains 10 C++ programs that demonstrate various programming concepts like arithmetic operators, if-else statements, loops, arrays, etc. Each program is presented with its source code and expected output.
// 7. Programto implement while loop and it computes a power of b
13
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float a;
int b;
float pow;
cout<<"nEnter the values : ";
cin>>a>>b;
pow=1.0;
while(b>=1)
{
pow=pow*a;
b--;
}
cout<<"Power : "<<pow;
getch();
}
// 8. Programto implement do while and it computes the factorial of a number
15
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,fact=1;
cout<<"nEnter the numnber : ";
cin>>num;
do
{
fact=fact*num;
num--;
}
while(num!=0);
cout<<"nFactorial :"<<fact;
getch();
}
// 10. Programto display multiples of a number using for loop
19
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,num;
cout<<"nEnter the number :";
cin>>num;
cout<<"The multiples are :";
for(i=1;i<=10;i++)
{
cout<<"n"<<num*i;
}
getch();
}