Sun May 25, 2008 5:03 pm
#include<iostream.h>
int fact(int x);
void main()
{
char y;
do
{
int x;
cout<<"plz,enter no."<<endl;
cin>>x;
cout<<fact(x)<<endl;
cout<<"do u want to try again(y/n)?";
a: cin>>y;
if (y!='y' && y!='n')
{
cout<<"plz enter y/n";
goto a;
}
}
while(y=='y');
}
int fact(int x)
{
int i,f=1;
for(i=1;i<=x;i++)
f*=i;
return f;
}
Sun Sep 07, 2008 2:45 am
#include<iostream>
int fact(int x);
using namespace std;
void main()
{
char y;
do
{
int x;
cout<<"plz,enter no."<<endl;
cin>>x;
cout<<fact(x)<<endl;
cout<<"do u want to try again(y/n)?";
cin>>y;
while (y!='y' && y!='n')
{
cout<<"plz enter y/n";
cin>>y;
}
}
while(y=='y');
}
int fact(int x)
{
int i,f=1;
for(i=1;i<=x;i++)
f*=i;
return f;
}
Sun Sep 07, 2008 3:03 am
Tue Sep 13, 2011 2:44 am
#include<iostream>
int fact(int x);
using namespace std;
void main()
{
char y;
do
{
int x;
cout<<"plz,enter no."<<endl;
cin>>x;
cout<<fact(x)<<endl;
cout<<"do u want to try again(y/n)?";
cin>>y;
while (y!='y' && y!='n')
{
cout<<"plz enter y/n";
cin>>y;
}
}
while(y=='y');
}
int fact(int x)
{
int i,f=1;
for(i=1;i<=x;i++)
f*=i;
return f;
}
Mon Sep 19, 2011 1:21 am
#include <iostream>
#include <iomanip>
using namespace std;
//GLOBAL VARIABLES
char y;
int n;
int f;
int counter = 0;
int main()
{
do
{
cout<<"Enter Number to be factored:";
cin>>n;
cin.clear();
cin.ignore(100,'\n');
if(n < 0) //IF THE NUMBER IS NEGATIVE LET THE USER KNOW
{
cout << "Error: you must enter a positive number to factor." << endl;
}
for(f = 2; f <= n; f++)
{
if(n % f == 0)
{
cout << setw(10) << f;
counter ++; //INCREASE COUNTER EVERY TIME LOOP EXECUTES
if(counter == 4)
{
cout << endl; //IF COUNTER EQUALS 4 OUTPUT END LINE
counter = 0; //RESET COUNTER TO 0 AFTER COUNTER REACHES 4
}
}
}
cout <<"\nWould you like to do another number (y/n)?" << endl;
cin>>y;
while (y!='y' && y!='n')
{
cout<<"Enter y = yes or n = no:";
cin>>y;
}
}
while(y == 'y'); //IF y WAS ENTERED START AGAIN ELSE PROGRAM WILL EXIT
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.