URI Problem # 1073 & 1164

URI Problem : 1073

Solution :

#include<stdio.h>
#include<math.h>
int main()
{
int n,i,even,sqr;
while(scanf("%d",&n)==1){
for(i=2;i<=n;i++){
if(i%2==0){
sqr=pow(i,2);
printf("%d^2 = %d\n",i,sqr);
}
}
}
return 0;
}
view raw gistfile1.c hosted with ❤ by GitHub


URI Problem : 1164

Solution :

#include<stdio.h>
int perfect_number(int n);
int main()
{
int n,i,test;
while(scanf("%d",&test)==1){
for(i=1;i<=test;i++){
scanf("%d",&n);
if(n==perfect_number(n)){
printf("%d eh perfeito\n",n);
}
else
printf("%d nao eh perfeito\n",n);
}
}
return 0;
}
int perfect_number(int n)
{
int i=1,per_num=0;
while(i<n){
if(n%i==0)
per_num=per_num+i;
i++;
}
if(per_num==n)
return n;
}
view raw gistfile1.c hosted with ❤ by GitHub

Related Posts: