kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Doubly-linked list_Traversal
Go: package main

import "fmt"

type dlNode struct {
    string
    next, prev *dlNode
}

type dlList struct {
    head, tail *dlNode
}

func (list *dlList) String() string {
    if list.head == nil {
        return fmt.Sprint(list.head)
    }
    r := "[" + list.head.string
    for p := list.head.next; p != nil; p = p.next {
        r += " " + p.string
    }
    return r + "]"
}

func (list *dlList) insertTail(node *dlNode) {
    if list.tail == nil {
        list.head = node
    } else {
        list.tail.next = node
    }
    node.next = nil
    node.prev = list.tail
    list.tail = node
}

func (list *dlList) insertAfter(existing, insert *dlNode) {
    insert.prev = existing
    insert.next = existing.next
    existing.next.prev = insert
    existing.next = insert
    if existing == list.tail {
        list.tail = insert
    }
}

func main() {
    dll := &dlList{}
    fmt.Println(dll)
    a := &dlNode{string: "A"}
    dll.insertTail(a)
    dll.insertTail(&dlNode{string: "B"})
    fmt.Println(dll)
    dll.insertAfter(a, &dlNode{string: "C"})
    fmt.Println(dll)

    
    fmt.Print("From tail:")
    for p := dll.tail; p != nil; p = p.prev {
        fmt.Print(" ", p.string)
    }
    fmt.Println("")
}

Java: package com.rosettacode;

import java.util.LinkedList;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class DoubleLinkedListTraversing {

  public static void main(String[] args) {

    final LinkedList<String> doubleLinkedList =
        IntStream.range(1, 10)
            .mapToObj(String::valueOf)
            .collect(Collectors.toCollection(LinkedList::new));

    doubleLinkedList.iterator().forEachRemaining(System.out::print);
    System.out.println();
    doubleLinkedList.descendingIterator().forEachRemaining(System.out::print);
  }
}
Task: Penney's game
C++: #include <time.h>
#include <iostream>
#include <string>

using namespace std;

class penney
{
public:
    penney()
    { pW = cW = 0;  }
    void gameLoop()
    {
	string a;
	while( true )
	{
	    playerChoice = computerChoice = "";
	    if( rand() % 2 ) 
	    { computer(); player(); }
	    else
	    { player(); computer(); }

	    play();

	    cout << "[Y] to play again "; cin >> a;
	    if( a[0] != 'Y' && a[0] != 'y' ) 
	    {
		cout << "Computer won " << cW << " times." << endl << "Player won " << pW << " times.";
		break;
	    }
	    cout << endl << endl;
        }
    }
private:
    void computer()
    {
        if( playerChoice.length() == 0 )
	{
	    for( int x = 0; x < 3; x++ )
		computerChoice.append( ( rand() % 2 ) ? "H" : "T", 1 );	
	}
	else
	{
	    computerChoice.append( playerChoice[1] == 'T' ? "H" : "T", 1 );
	    computerChoice += playerChoice.substr( 0, 2 );
	}
	cout << "Computer's sequence of three is: " << computerChoice << endl;
    }
    void player()
    {
	cout << "Enter your sequence of three (H/T) "; cin >> playerChoice;
    }
    void play()
    {
	sequence = "";
	while( true )
	{
	    sequence.append( ( rand() % 2 ) ? "H" : "T", 1 );
	    if( sequence.find( playerChoice ) != sequence.npos )
	    {
		showWinner( 1 );
		break;
	    }
	    else if( sequence.find( computerChoice ) != sequence.npos )
	    {
		showWinner( 0 );
		break;
	    }
	}
    }
    void showWinner( int i )
    {
	string s;
	if( i ) { s = "Player wins!"; pW++; }
	else { s = "Computer wins!"; cW++; }
	cout << "Tossed sequence: " << sequence << endl << s << endl << endl;
    }
    string playerChoice, computerChoice, sequence;
    int pW, cW;
};
int main( int argc, char* argv[] )
{
    srand( static_cast<unsigned>( time( NULL ) ) );
    penney game; game.gameLoop();
    return 0;
}

Go: package main
import "fmt"
import "math/rand"
func main(){
var a1,a2,a3,y,match,j,k int
var inp string
y=1
for y==1{
fmt.Println("Enter your sequence:")
fmt.Scanln(&inp)
var Ai [3] int
var user [3] int
for j=0;j<3;j++{
if(inp[j]==104){
user[j]=1
}else{
user[j]=0
}
}
for k=0;k<3;k++{
Ai[k]=rand.Intn(2)
}
for user[0]==Ai[0]&&user[1]==Ai[1]&&user[2]==Ai[2]{
for k=0;k<3;k++{
Ai[k]=rand.Intn(2)
}
}
fmt.Println("You gave the sequence:")
printht(user)
fmt.Println()
fmt.Println("The computer generated sequence is:")
printht(Ai)
fmt.Println()
a1=rand.Intn(2)
a2=rand.Intn(2)
a3=rand.Intn(2)
fmt.Print("The generated sequence is:")
printh(a1)
printh(a2)
printh(a3)
match=0
for match==0{
if(matches(user,a1,a2,a3)==1){
fmt.Println()
fmt.Println("You have won!!!")
match=1
}else if(matches(Ai,a1,a2,a3)==1){
fmt.Println()
fmt.Println("You lost!! Computer wins")
match=1
}else{
a1=a2
a2=a3
a3=rand.Intn(2)
printh(a3)
}
}
fmt.Println("Do you want to continue(0/1):")
fmt.Scanln(&y)
}
}
func printht(a [3] int) int{
var i int
for i=0;i<3;i++{
if(a[i]==1){
fmt.Print("h")
}else{
fmt.Print("t")
}
}
return 1
}
func printh(a int) int{
if(a==1){
fmt.Print("h")
}else{
fmt.Print("t")
}
return 1
}
func matches(a [3] int,p int,q int,r int) int{
if(a[0]==p&&a[1]==q&&a[2]==r){
return 1
}else{
return 0
}
}
Task: Penney's game
Go: package main
import "fmt"
import "math/rand"
func main(){
var a1,a2,a3,y,match,j,k int
var inp string
y=1
for y==1{
fmt.Println("Enter your sequence:")
fmt.Scanln(&inp)
var Ai [3] int
var user [3] int
for j=0;j<3;j++{
if(inp[j]==104){
user[j]=1
}else{
user[j]=0
}
}
for k=0;k<3;k++{
Ai[k]=rand.Intn(2)
}
for user[0]==Ai[0]&&user[1]==Ai[1]&&user[2]==Ai[2]{
for k=0;k<3;k++{
Ai[k]=rand.Intn(2)
}
}
fmt.Println("You gave the sequence:")
printht(user)
fmt.Println()
fmt.Println("The computer generated sequence is:")
printht(Ai)
fmt.Println()
a1=rand.Intn(2)
a2=rand.Intn(2)
a3=rand.Intn(2)
fmt.Print("The generated sequence is:")
printh(a1)
printh(a2)
printh(a3)
match=0
for match==0{
if(matches(user,a1,a2,a3)==1){
fmt.Println()
fmt.Println("You have won!!!")
match=1
}else if(matches(Ai,a1,a2,a3)==1){
fmt.Println()
fmt.Println("You lost!! Computer wins")
match=1
}else{
a1=a2
a2=a3
a3=rand.Intn(2)
printh(a3)
}
}
fmt.Println("Do you want to continue(0/1):")
fmt.Scanln(&y)
}
}
func printht(a [3] int) int{
var i int
for i=0;i<3;i++{
if(a[i]==1){
fmt.Print("h")
}else{
fmt.Print("t")
}
}
return 1
}
func printh(a int) int{
if(a==1){
fmt.Print("h")
}else{
fmt.Print("t")
}
return 1
}
func matches(a [3] int,p int,q int,r int) int{
if(a[0]==p&&a[1]==q&&a[2]==r){
return 1
}else{
return 0
}
}

Java: import java.util.*;

public class PenneysGame {

    public static void main(String[] args) {
        Random rand = new Random();

        String compChoice = "", playerChoice;
        if (rand.nextBoolean()) {

            for (int i = 0; i < 3; i++)
                compChoice += "HT".charAt(rand.nextInt(2));
            System.out.printf("Computer chooses %s%n", compChoice);

            playerChoice = prompt(compChoice);

        } else {

            playerChoice = prompt(compChoice);

            compChoice = "T";
            if (playerChoice.charAt(1) == 'T')
                compChoice = "H";
            compChoice += playerChoice.substring(0, 2);
            System.out.printf("Computer chooses %s%n", compChoice);
        }

        String tossed = "";
        while (true) {
            tossed += "HT".charAt(rand.nextInt(2));
            System.out.printf("Tossed %s%n" , tossed);
            if (tossed.endsWith(playerChoice)) {
                System.out.println("You win!");
                break;
            }
            if (tossed.endsWith(compChoice)) {
                System.out.println("Computer wins!");
                break;
            }
        }
    }

    private static String prompt(String otherChoice) {
        Scanner sc = new Scanner(System.in);
        String s;
        do {
            System.out.print("Choose a sequence: ");
            s = sc.nextLine().trim().toUpperCase();
        } while (!s.matches("[HT]{3}") || s.equals(otherChoice));
        return s;
    }
}
Task: Penney's game
Java: import java.util.*;

public class PenneysGame {

    public static void main(String[] args) {
        Random rand = new Random();

        String compChoice = "", playerChoice;
        if (rand.nextBoolean()) {

            for (int i = 0; i < 3; i++)
                compChoice += "HT".charAt(rand.nextInt(2));
            System.out.printf("Computer chooses %s%n", compChoice);

            playerChoice = prompt(compChoice);

        } else {

            playerChoice = prompt(compChoice);

            compChoice = "T";
            if (playerChoice.charAt(1) == 'T')
                compChoice = "H";
            compChoice += playerChoice.substring(0, 2);
            System.out.printf("Computer chooses %s%n", compChoice);
        }

        String tossed = "";
        while (true) {
            tossed += "HT".charAt(rand.nextInt(2));
            System.out.printf("Tossed %s%n" , tossed);
            if (tossed.endsWith(playerChoice)) {
                System.out.println("You win!");
                break;
            }
            if (tossed.endsWith(compChoice)) {
                System.out.println("Computer wins!");
                break;
            }
        }
    }

    private static String prompt(String otherChoice) {
        Scanner sc = new Scanner(System.in);
        String s;
        do {
            System.out.print("Choose a sequence: ");
            s = sc.nextLine().trim().toUpperCase();
        } while (!s.matches("[HT]{3}") || s.equals(otherChoice));
        return s;
    }
}

Python: from __future__ import print_function
import random
from time import sleep

first = random.choice([True, False])

you = ''
if first:
    me = ''.join(random.sample('HT'*3, 3))
    print('I choose first and will win on first seeing {} in the list of tosses'.format(me))
    while len(you) != 3 or any(ch not in 'HT' for ch in you) or you == me:
        you = input('What sequence of three Heads/Tails will you win with: ')
else:
    while len(you) != 3 or any(ch not in 'HT' for ch in you):
        you = input('After you: What sequence of three Heads/Tails will you win with: ')
    me = ('H' if you[1] == 'T' else 'T') + you[:2]
    print('I win on first seeing {} in the list of tosses'.format(me))
    
print('Rolling:\n  ', end='')
rolled = ''
while True:
    rolled += random.choice('HT')
    print(rolled[-1], end='')
    if rolled.endswith(you):
        print('\n  You win!')
        break
    if rolled.endswith(me):
        print('\n  I win!')
        break
    sleep(1)
Task: Penney's game
Go: package main
import "fmt"
import "math/rand"
func main(){
var a1,a2,a3,y,match,j,k int
var inp string
y=1
for y==1{
fmt.Println("Enter your sequence:")
fmt.Scanln(&inp)
var Ai [3] int
var user [3] int
for j=0;j<3;j++{
if(inp[j]==104){
user[j]=1
}else{
user[j]=0
}
}
for k=0;k<3;k++{
Ai[k]=rand.Intn(2)
}
for user[0]==Ai[0]&&user[1]==Ai[1]&&user[2]==Ai[2]{
for k=0;k<3;k++{
Ai[k]=rand.Intn(2)
}
}
fmt.Println("You gave the sequence:")
printht(user)
fmt.Println()
fmt.Println("The computer generated sequence is:")
printht(Ai)
fmt.Println()
a1=rand.Intn(2)
a2=rand.Intn(2)
a3=rand.Intn(2)
fmt.Print("The generated sequence is:")
printh(a1)
printh(a2)
printh(a3)
match=0
for match==0{
if(matches(user,a1,a2,a3)==1){
fmt.Println()
fmt.Println("You have won!!!")
match=1
}else if(matches(Ai,a1,a2,a3)==1){
fmt.Println()
fmt.Println("You lost!! Computer wins")
match=1
}else{
a1=a2
a2=a3
a3=rand.Intn(2)
printh(a3)
}
}
fmt.Println("Do you want to continue(0/1):")
fmt.Scanln(&y)
}
}
func printht(a [3] int) int{
var i int
for i=0;i<3;i++{
if(a[i]==1){
fmt.Print("h")
}else{
fmt.Print("t")
}
}
return 1
}
func printh(a int) int{
if(a==1){
fmt.Print("h")
}else{
fmt.Print("t")
}
return 1
}
func matches(a [3] int,p int,q int,r int) int{
if(a[0]==p&&a[1]==q&&a[2]==r){
return 1
}else{
return 0
}
}

Python: from __future__ import print_function
import random
from time import sleep

first = random.choice([True, False])

you = ''
if first:
    me = ''.join(random.sample('HT'*3, 3))
    print('I choose first and will win on first seeing {} in the list of tosses'.format(me))
    while len(you) != 3 or any(ch not in 'HT' for ch in you) or you == me:
        you = input('What sequence of three Heads/Tails will you win with: ')
else:
    while len(you) != 3 or any(ch not in 'HT' for ch in you):
        you = input('After you: What sequence of three Heads/Tails will you win with: ')
    me = ('H' if you[1] == 'T' else 'T') + you[:2]
    print('I win on first seeing {} in the list of tosses'.format(me))
    
print('Rolling:\n  ', end='')
rolled = ''
while True:
    rolled += random.choice('HT')
    print(rolled[-1], end='')
    if rolled.endswith(you):
        print('\n  You win!')
        break
    if rolled.endswith(me):
        print('\n  I win!')
        break
    sleep(1)
Task: Penney's game
C++: #include <time.h>
#include <iostream>
#include <string>

using namespace std;

class penney
{
public:
    penney()
    { pW = cW = 0;  }
    void gameLoop()
    {
	string a;
	while( true )
	{
	    playerChoice = computerChoice = "";
	    if( rand() % 2 ) 
	    { computer(); player(); }
	    else
	    { player(); computer(); }

	    play();

	    cout << "[Y] to play again "; cin >> a;
	    if( a[0] != 'Y' && a[0] != 'y' ) 
	    {
		cout << "Computer won " << cW << " times." << endl << "Player won " << pW << " times.";
		break;
	    }
	    cout << endl << endl;
        }
    }
private:
    void computer()
    {
        if( playerChoice.length() == 0 )
	{
	    for( int x = 0; x < 3; x++ )
		computerChoice.append( ( rand() % 2 ) ? "H" : "T", 1 );	
	}
	else
	{
	    computerChoice.append( playerChoice[1] == 'T' ? "H" : "T", 1 );
	    computerChoice += playerChoice.substr( 0, 2 );
	}
	cout << "Computer's sequence of three is: " << computerChoice << endl;
    }
    void player()
    {
	cout << "Enter your sequence of three (H/T) "; cin >> playerChoice;
    }
    void play()
    {
	sequence = "";
	while( true )
	{
	    sequence.append( ( rand() % 2 ) ? "H" : "T", 1 );
	    if( sequence.find( playerChoice ) != sequence.npos )
	    {
		showWinner( 1 );
		break;
	    }
	    else if( sequence.find( computerChoice ) != sequence.npos )
	    {
		showWinner( 0 );
		break;
	    }
	}
    }
    void showWinner( int i )
    {
	string s;
	if( i ) { s = "Player wins!"; pW++; }
	else { s = "Computer wins!"; cW++; }
	cout << "Tossed sequence: " << sequence << endl << s << endl << endl;
    }
    string playerChoice, computerChoice, sequence;
    int pW, cW;
};
int main( int argc, char* argv[] )
{
    srand( static_cast<unsigned>( time( NULL ) ) );
    penney game; game.gameLoop();
    return 0;
}

Python: from __future__ import print_function
import random
from time import sleep

first = random.choice([True, False])

you = ''
if first:
    me = ''.join(random.sample('HT'*3, 3))
    print('I choose first and will win on first seeing {} in the list of tosses'.format(me))
    while len(you) != 3 or any(ch not in 'HT' for ch in you) or you == me:
        you = input('What sequence of three Heads/Tails will you win with: ')
else:
    while len(you) != 3 or any(ch not in 'HT' for ch in you):
        you = input('After you: What sequence of three Heads/Tails will you win with: ')
    me = ('H' if you[1] == 'T' else 'T') + you[:2]
    print('I win on first seeing {} in the list of tosses'.format(me))
    
print('Rolling:\n  ', end='')
rolled = ''
while True:
    rolled += random.choice('HT')
    print(rolled[-1], end='')
    if rolled.endswith(you):
        print('\n  You win!')
        break
    if rolled.endswith(me):
        print('\n  I win!')
        break
    sleep(1)
Task: Babbage problem
C#: namespace Babbage_Problem
{
    class iterateNumbers
    {
        public iterateNumbers()
        {
            long baseNumberSquared = 0; 
            long baseNumber = 0;  

            do  
            {
                baseNumber += 1; 
                baseNumberSquared = baseNumber * baseNumber; 
            }
            while (Right6Digits(baseNumberSquared) != 269696); 

            Console.WriteLine("The smallest integer whose square ends in 269,696 is " + baseNumber);
            Console.WriteLine("The square is " + baseNumberSquared);

        }

        private long Right6Digits(long baseNumberSquared)
        {

            string numberAsString = baseNumberSquared.ToString(); 

            if (numberAsString.Length < 6) { return baseNumberSquared; }; 

            numberAsString = numberAsString.Substring(numberAsString.Length - 6);  

            return long.Parse(numberAsString); 

        }
    }
}}

C++: #include <iostream>

int main( ) {
   int current = 0 ;
   while ( ( current * current ) % 1000000 != 269696 ) 
      current++ ;
   std::cout << "The square of " << current << " is " << (current * current) << " !\n" ;
   return 0 ;
}
Task: Babbage problem
C++: #include <iostream>

int main( ) {
   int current = 0 ;
   while ( ( current * current ) % 1000000 != 269696 ) 
      current++ ;
   std::cout << "The square of " << current << " is " << (current * current) << " !\n" ;
   return 0 ;
}

Java: public class Test {

    public static void main(String[] args) {

        
        int n = 0;

        
        do {

            
            n++;

        
        } while (n * n % 1000_000 != 269696);

        
        System.out.println(n);
    }
}
Task: Babbage problem
C++: #include <iostream>

int main( ) {
   int current = 0 ;
   while ( ( current * current ) % 1000000 != 269696 ) 
      current++ ;
   std::cout << "The square of " << current << " is " << (current * current) << " !\n" ;
   return 0 ;
}

Python: 


n=0 




while n**2 % 1000000 != 269696:

    
    
    
    
    n += 1 

print(n)
Task: Babbage problem
C#: namespace Babbage_Problem
{
    class iterateNumbers
    {
        public iterateNumbers()
        {
            long baseNumberSquared = 0; 
            long baseNumber = 0;  

            do  
            {
                baseNumber += 1; 
                baseNumberSquared = baseNumber * baseNumber; 
            }
            while (Right6Digits(baseNumberSquared) != 269696); 

            Console.WriteLine("The smallest integer whose square ends in 269,696 is " + baseNumber);
            Console.WriteLine("The square is " + baseNumberSquared);

        }

        private long Right6Digits(long baseNumberSquared)
        {

            string numberAsString = baseNumberSquared.ToString(); 

            if (numberAsString.Length < 6) { return baseNumberSquared; }; 

            numberAsString = numberAsString.Substring(numberAsString.Length - 6);  

            return long.Parse(numberAsString); 

        }
    }
}}

Java: public class Test {

    public static void main(String[] args) {

        
        int n = 0;

        
        do {

            
            n++;

        
        } while (n * n % 1000_000 != 269696);

        
        System.out.println(n);
    }
}
Task: Babbage problem
C#: namespace Babbage_Problem
{
    class iterateNumbers
    {
        public iterateNumbers()
        {
            long baseNumberSquared = 0; 
            long baseNumber = 0;  

            do  
            {
                baseNumber += 1; 
                baseNumberSquared = baseNumber * baseNumber; 
            }
            while (Right6Digits(baseNumberSquared) != 269696); 

            Console.WriteLine("The smallest integer whose square ends in 269,696 is " + baseNumber);
            Console.WriteLine("The square is " + baseNumberSquared);

        }

        private long Right6Digits(long baseNumberSquared)
        {

            string numberAsString = baseNumberSquared.ToString(); 

            if (numberAsString.Length < 6) { return baseNumberSquared; }; 

            numberAsString = numberAsString.Substring(numberAsString.Length - 6);  

            return long.Parse(numberAsString); 

        }
    }
}}

Python: 


n=0 




while n**2 % 1000000 != 269696:

    
    
    
    
    n += 1 

print(n)
Task: Babbage problem
C#: namespace Babbage_Problem
{
    class iterateNumbers
    {
        public iterateNumbers()
        {
            long baseNumberSquared = 0; 
            long baseNumber = 0;  

            do  
            {
                baseNumber += 1; 
                baseNumberSquared = baseNumber * baseNumber; 
            }
            while (Right6Digits(baseNumberSquared) != 269696); 

            Console.WriteLine("The smallest integer whose square ends in 269,696 is " + baseNumber);
            Console.WriteLine("The square is " + baseNumberSquared);

        }

        private long Right6Digits(long baseNumberSquared)
        {

            string numberAsString = baseNumberSquared.ToString(); 

            if (numberAsString.Length < 6) { return baseNumberSquared; }; 

            numberAsString = numberAsString.Substring(numberAsString.Length - 6);  

            return long.Parse(numberAsString); 

        }
    }
}}

VB: Sub Baggage_Problem()
Dim i As Long

    
    i = 520
    
    
    Do While ((i * i) Mod 1000000) <> 269696
        i = i + 4 
    Loop
    Debug.Print "The smallest positive integer whose square ends in the digits 269 696 is : " & i & vbCrLf & _
    "Its square is : " & i * i
End Sub
Task: Babbage problem
Java: public class Test {

    public static void main(String[] args) {

        
        int n = 0;

        
        do {

            
            n++;

        
        } while (n * n % 1000_000 != 269696);

        
        System.out.println(n);
    }
}

Python: 


n=0 




while n**2 % 1000000 != 269696:

    
    
    
    
    n += 1 

print(n)
Task: Babbage problem
Python: 


n=0 




while n**2 % 1000000 != 269696:

    
    
    
    
    n += 1 

print(n) 

VB: Sub Baggage_Problem()
Dim i As Long

    
    i = 520
    
    
    Do While ((i * i) Mod 1000000) <> 269696
        i = i + 4 
    Loop
    Debug.Print "The smallest positive integer whose square ends in the digits 269 696 is : " & i & vbCrLf & _
    "Its square is : " & i * i
End Sub
Task: Babbage problem
C++: #include <iostream>

int main( ) {
   int current = 0 ;
   while ( ( current * current ) % 1000000 != 269696 ) 
      current++ ;
   std::cout << "The square of " << current << " is " << (current * current) << " !\n" ;
   return 0 ;
}

VB: Sub Baggage_Problem()
Dim i As Long

    
    i = 520
    
    
    Do While ((i * i) Mod 1000000) <> 269696
        i = i + 4 
    Loop
    Debug.Print "The smallest positive integer whose square ends in the digits 269 696 is : " & i & vbCrLf & _
    "Its square is : " & i * i
End Sub
Task: Babbage problem
Java: public class Test {

    public static void main(String[] args) {

        
        int n = 0;

        
        do {

            
            n++;

        
        } while (n * n % 1000_000 != 269696);

        
        System.out.println(n);
    }
}

VB: Sub Baggage_Problem()
Dim i As Long

    
    i = 520
    
    
    Do While ((i * i) Mod 1000000) <> 269696
        i = i + 4 
    Loop
    Debug.Print "The smallest positive integer whose square ends in the digits 269 696 is : " & i & vbCrLf & _
    "Its square is : " & i * i
End Sub
Task: Almost prime
C: #include <stdio.h>

int kprime(int n, int k)
{
	int p, f = 0;
	for (p = 2; f < k && p*p <= n; p++)
		while (0 == n % p)
			n /= p, f++;

	return f + (n > 1) == k;
}

int main(void)
{
	int i, c, k;

	for (k = 1; k <= 5; k++) {
		printf("k = %d:", k);

		for (i = 2, c = 0; c < 10; i++)
			if (kprime(i, k)) {
				printf(" %d", i);
				c++;
			}

		putchar('\n');
	}

	return 0;
}

C++: #include <cstdlib>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <list>

bool k_prime(unsigned n, unsigned k) {
    unsigned f = 0;
    for (unsigned p = 2; f < k && p * p <= n; p++)
        while (0 == n % p) { n /= p; f++; }
    return f + (n > 1 ? 1 : 0) == k;
}

std::list<unsigned> primes(unsigned k, unsigned n)  {
    std::list<unsigned> list;
    for (unsigned i = 2;list.size() < n;i++)
        if (k_prime(i, k)) list.push_back(i);
    return list;
}

int main(const int argc, const char* argv[]) {
    using namespace std;
    for (unsigned k = 1; k <= 5; k++) {
        ostringstream os("");
        const list<unsigned> l = primes(k, 10);
        for (list<unsigned>::const_iterator i = l.begin(); i != l.end(); i++)
            os << setw(4) << *i;
        cout << "k = " << k << ':' << os.str() << endl;
    }

	return EXIT_SUCCESS;
}