uva problem 100 solution in c
seeing this source code of uva 100 after trying hard.if you cannot solve the problem ,then you can see this source code.
// uva 100.cpp : Defines the entry point for the console application.
//
//md.anis molla
//university of barisal 5th batch
#include "stdafx.h"
# include<iostream>
using namespace std;
int main()
{
int i, j, m, n, t, c = 1, d;
int sum=0;
//cin >> n;
//cin >> m;
scanf("%d%d", &n, &m);
printf("%d %d ", n, m);
if (n > m) {
t = m;
m = n;
n = t;
}
for (i = n;i <= m;i++) {
c = 1;
for(j=i;j!=1;j=j){
if (j % 2 == 0) {
j = j / 2;
}
else {
j = 3 * j + 1;
}
c = c + 1;
}
if (c >= sum)sum=c;
}
printf("%d\n", sum);
return 0;
}
// uva 100.cpp : Defines the entry point for the console application.
//
//md.anis molla
//university of barisal 5th batch
#include "stdafx.h"
# include<iostream>
using namespace std;
int main()
{
int i, j, m, n, t, c = 1, d;
int sum=0;
//cin >> n;
//cin >> m;
scanf("%d%d", &n, &m);
printf("%d %d ", n, m);
if (n > m) {
t = m;
m = n;
n = t;
}
for (i = n;i <= m;i++) {
c = 1;
for(j=i;j!=1;j=j){
if (j % 2 == 0) {
j = j / 2;
}
else {
j = 3 * j + 1;
}
c = c + 1;
}
if (c >= sum)sum=c;
}
printf("%d\n", sum);
return 0;
}
Comments
Post a Comment