URI -- Problem No : 1030,1096 & 1116

Problem No : 1030

Problem Name : Flavious Josephus Legend

Solution :

#include<stdio.h>
int josephus(int n,int k);
int main()
{
int tcase,n,k,i;
while(scanf("%d",&tcase)==1){
for(i=1;i<=tcase;i++){
scanf("%d %d",&n,&k);
int tmp=josephus(n,k);
printf("Case %d: %d\n",i,tmp);
}
}
return 0;
}
int josephus(int n,int k)
{
if(n==1)
return 1;
else
return (josephus(n-1,k)+k-1)%n+1;
}
view raw URI 1030 hosted with ❤ by GitHub


Problem No : 1116

Problem Name : Dividing X by Y

Solution :

#include<stdio.h>
int main()
{
int t,n,m;
double d;
scanf("%d",&t);
while(t--){
scanf("%d %d",&n,&m);
if(m==0)
printf("divisao impossivel\n");
else{
d=(double) n/m;
printf("%.1lf\n",d);
}
}
return 0;
}
view raw URI 1116 hosted with ❤ by GitHub


Problem No : 1096

Problem Name : Sequence IJ 2

Solution :

#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=9;i=i+2){
for(j=7;j>=5;j--){
printf("I=%d J=%d\n",i,j);
}
}
return 0;
}

Related Posts: