Skip to content

Instantly share code, notes, and snippets.

@Manume
Manume / sum of all the primes below two million.rb
Last active August 29, 2015 14:02
program to Find the sum of all the primes below two million.
class Prime
require'mathn'
max = 2_000_000
sum = 0
Prime.each { |x|
break if x >= max;
sum+=x
}
@Manume
Manume / sum_and_square.rb
Last active August 29, 2015 14:02
difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
#difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
class Sum
def self.sum(number_set)
sum = (number_set).map { |i| i*i }.reduce(:+)
#put here the sum of squares of the numbers
return sum
end
def self.square(number_set)
square = (number_set).reduce(:+)**2
@Manume
Manume / primefactor using class.rb
Last active August 29, 2015 14:02
Find the biggest primefactor using class
#to find the biggest prime number
class Prime
def initialize(num)
puts "input value is #{num}"
end
def primefactor(n)
i=2
largest=0
while(i<=n)
if(n%i==0)
@Manume
Manume / prime_factor.rb
Created June 4, 2014 06:33
Ruby program to find largest prime factor
#To find the biggest frame
require 'prime'
max = 600851475143; test = 3
while (max >= test) do
if (test.prime? && (max % test == 0))
best = test
max = max / test
else
@Manume
Manume / primefactor.rb
Created June 4, 2014 05:08
Ruby program to find largest prime factor
#Ruby program for find the prime factor of 600851475143
def gen_prime_factors(num)
result = []
2.upto(num-1) do |i|
result.push i if num % i == 0
puts "Prime factor found: #{i}"
end
result
@Manume
Manume / addition.rb
Last active August 29, 2015 14:01
addition of two number using ruby
puts"enter the first value"
a=gets.to_i
puts"enter the second value"
b=gets.to_i
c=a+b
puts"The output is :#{c}"
@Manume
Manume / Program to count the number of words and characters in a sentence
Created May 21, 2014 10:32
Program to count the number of words and characters in a sentence
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int countch=0;
int countwd=1;
cout << "Enter your sentence in lowercase: " << endl;
char ch='a';
@Manume
Manume / sum of two numbers
Created May 21, 2014 10:22
sum of two numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,s;
cout<<"enter two numbers";
cin>>a>>b;
s=a+b;
cout<<"the sum of two number is"<<s;
getch();
@Manume
Manume / Program to print the first 10 lines of pascal's triangle
Created May 21, 2014 10:18
Program to print the first 10 lines of pascal's triangle
#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
long triangle(int x,int y);
int main()
{
clrscr();
const lines=10;
for (int i=0;i<lines;i++)
for (int j=1;j<lines-i;j++)
@Manume
Manume / program to find the length of string
Last active August 29, 2015 14:01
program to find the length of string
#include <iostream.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
int slength;
char x[81]; //Allowing the user to input a maximum of 80 characters.
cout << "Enter the string : " << endl;