This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Prime | |
require'mathn' | |
max = 2_000_000 | |
sum = 0 | |
Prime.each { |x| | |
break if x >= max; | |
sum+=x | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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++) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; |
NewerOlder