Yes...
Posted: Tue Mar 04, 2008 9:06 am
So many thank's I got Accepted... 

Code: Select all
#include <iostream>
using namespace std;
int main()
{
int n,a,b,i,j=0,k,count=1;
while( cin>>n)
{
count=1;
if(j==0)
cout<<"PERFECTION OUTPUT"<<endl;
if(n==0)
{
cout<<"END OF OUTPUT"<<endl;
break;
}
for(i=2;i<=n/2;i++)
{
if(n%i==0)
count=count+i;
else
continue;
}
if(count==n)
cout<<n<<" PERFECT"<<endl;
else if (count>n)
cout<<n<<" ABUNDANT"<<endl;
else
cout<<n<<" DEFICIENT"<<endl;
j++;
}
return 0;
}
Code: Select all
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n,a,b,i,j=0,k,count=1;
while( cin>>n)
{
count=1;
if(j==0)
cout<<"PERFECTION OUTPUT"<<endl;
if(n==0)
{
cout<<"END OF OUTPUT"<<endl;
break;
}
for(i=2;i<=n/2;i++)
{
if(n%i==0)
count=count+i;
else
continue;
}
if(count==n)
//cout<<n<<" PERFECT"<<endl;
printf("%5d PERFECT\n", n);
else if (count>n)
//cout<<n<<" ABUNDANT"<<endl;
printf("%5d ABUNDANT\n", n);
else
//cout<<n<<" DEFICIENT"<<endl;
printf("%5d DEFICIENT\n", n);
j++;
}
return 0;
}
In ur code there r two wrong thing
no one :
chang this lineToCode: Select all
count = 1;
andCode: Select all
count =0;
ToCode: Select all
for(i=2;i<=n/2;i++)
another thing u must have to change.......Code: Select all
for(i=1;i<=n/2;i++)
change it toCode: Select all
if(count==n) //cout<<n<<" PERFECT"<<endl; printf("%5d PERFECT\n", n); else if (count>n) //cout<<n<<" ABUNDANT"<<endl; printf("%5d ABUNDANT\n", n); else //cout<<n<<" DEFICIENT"<<endl; printf("%5d DEFICIENT\n", n);
That is printf("%5d##DEFICIENT\n", n);Code: Select all
if(count==n) printf("%5d PERFECT\n", n); else if (count>n) printf("%5d ABUNDANT\n", n); else printf("%5d DEFICIENT\n", n);
here # means space
And after ACC PLZ remove ur code....![]()
Code: Select all
#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;
//functions
void listOfDivisors(unsigned int givenNum);
int caseCounter=0;
unsigned int isPerfectOrAbundOrDef(unsigned int l);
string numberOfSpaces(unsigned int givenNum);
unsigned int arrayOfDivisors[20000];
int main()
{
unsigned int givenNum;
while (scanf("%d",&givenNum)==1)
{
if (givenNum==0)
{
cout<<"END OF OUTPUT";
break;
}
listOfDivisors(givenNum);
unsigned int result=isPerfectOrAbundOrDef(givenNum);
if(caseCounter==0) cout<<"PERFECTION OUTPUT"<<endl;
caseCounter++;
if (result==0) cout<< numberOfSpaces(givenNum) << givenNum <<" PERFECT"<<endl;
else if (result==1) cout << numberOfSpaces(givenNum) << givenNum <<" ABUNDANT"<<endl;
else cout << numberOfSpaces(givenNum) <<givenNum<<" DEFICIENT"<<endl;
for (unsigned int j=0;j<20000 ;j++ )
{
arrayOfDivisors[j]=0;
}
}
return 0;
}
unsigned int isPerfectOrAbundOrDef(unsigned int l)
{
unsigned int sumOfDivisors=0;
for (unsigned int i=0;i<20000 ;i++ )
{
sumOfDivisors=sumOfDivisors+arrayOfDivisors[i];
}
if (sumOfDivisors>l) return 1;
else if (sumOfDivisors==l) return 0;
else return -1;
}
void listOfDivisors(unsigned int givenNum)
{
unsigned int i=0;
for (unsigned int l=1; l<= int(givenNum/2);l++)
{
if ((givenNum%l)==0)
{
arrayOfDivisors[i]=l;
i++;
}
}
}
string numberOfSpaces(unsigned int givenNum)
{
string numOfSpaces;
unsigned int i=ceil(log10(givenNum));
if(i==5) numOfSpaces=numOfSpaces+"";
else if(i==4) numOfSpaces=numOfSpaces+" ";
else if(i==3) numOfSpaces=numOfSpaces+" ";
else if(i==2) numOfSpaces=numOfSpaces+" ";
else if(i==1) numOfSpaces=numOfSpaces+" ";
return numOfSpaces;
}
Code: Select all
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
long i, num,sum;
int list[100];
char input[50000];
int main() {
gets(input);
char *p;
printf("PERFECTION OUTPUT\n");
p = strtok(input," ");
while( p != NULL )
{
num = atol( p);
if(num == 0)
break;
sum = 0;
for( i = 1; i <= num/2; i++) {
if( num %i == 0) {
sum = sum + i;
}
}
if(num == sum) {
printf("%5d PERFECT\n", num);
}
else if( num < sum) {
printf("%5d ABUNDANT\n", num);
}
else if( num > sum) {
printf("%5d DEFICIENT\n", num);
}
p = strtok(NULL," ");
}
printf("END OF OUTPUT\n");
return 0;
}