Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Converting C Code to Abap

Arslan1
Explorer
0 Likes
3,548
#include <stdio.h>
#include <stdlib.h>
 
// N, 2 boyutlu matrisin boyutudur N*N
#N 9'u tanımı
 
/* Izgarayı yazdırmak için bir yardımcı fonksiyon */
void print(int arr[N][N])
{
     for (int i = 0; i < N; i++)
      {
         for (int j = 0; j < N; j++)
            printf("%d",dizi[i][j]);
         printf("\n");
       }
}
 
// Yasal'ın olup olmayacağını kontrol ediyoruz 
// sayıyı atamak için
// verilen satır, sütun
int isSafe(int grid[N][N], int satır,
                       int sütun, int sayı)
{
     
    // Aynı sayıyı bulup bulmadığımızı kontrol edin
    // benzer satırda 0 deÄŸeri döndürüyoruz
    for (int x = 0; x <= 8; x++)
        if (ızgara[satır][x] == sayı)
            0 deÄŸeri döndürme;
 
    // Aynı sayıyı bulup bulmadığımızı kontrol edin
    // benzer sütun, 0 döndürüyoruz
    for (int x = 0; x <= 8; x++)
        if (ızgara[x][sütun] == sayı)
            0 deÄŸeri döndürme;
 
    // Aynı sayıyı bulup bulmadığımızı kontrol edin
    // belirli bir 3*3 matrisi, 0 deÄŸeri dönerüz
    int startRow = satır - satır % 3,
                 startCol = sütun - sütun % 3;
   
    for (int i = 0; i < 3; i++)
        for (int j = 0; j < 3; j++)
            if (grid[i + startRow][j +
                          startCol] == sayı)
                0 deÄŸeri döndürme;
 
    1'i döndür;
}
 
/* Kısmen doldurulmuş bir ızgarayı alır ve denemeye çalışırız
İçindeki tüm atanmamış konumlara değer atamak için
gelecek ÅŸekilde
Sudoku çözümü (satırlar arasında çoğaltılması,
sütunlar ve kutular) */
int solventSudoku(int grid[N][N], int satır, int sütun)
{
     
    // 8. sıraya ulaşıp ulaÅŸmadığımızı kontrol edin
    // ve 9. sütun (0
    // indekslenmiÅŸ matris) , biz
    // miktarı için gerçek deÄŸeri döndürüyoruz
    // daha fazla geri izleme
    if (satır == N - 1 && sütun == N)
        1'i döndür;
 
    // Sütunun 9 olup olmadığını kontrol edin,
    //sonraki satıra geçiyoruz ve
    // sütun 0'dan baÅŸlıyor
    eÄŸer (sütun == N)
    {
        satır++;
        sütunu = 0;
    }
   
    // durumun konumunun olup olmadığını kontrol edin
    // ızgaranın zaten benzerleri
    // deÄŸer >0, sonraki sütun için yineliyoruz
    if (ızgara[satır][sütun] > 0)
        return solventSudoku(ızgara, satır, sütun + 1);
 
    for (int sayı = 1; sayı <= N; sayı++)
    {
         
        // YerleÅŸtirmenin güvenli olup olmadığını kontrol edin
        // İçindeki sayı (1-9)
        // verilen satır ,col ->sonraki sütuna geçiyoruz
        if (isSafe(ızgara, satır, sütun, sayı)==1)
        {
            /* sayıyı atamak
               zorunludur (satır, sütun)
               Ä±zgara konumu
               ve atanan numaramızı varsayarsak
               burada
               doÄŸru */
            grid[satır][sütun] = sayı;
           
            // sonraki ile sonraki olasılık kontrol ediyoruz
            // sütun
            if (solveSudoku(ızgara, satır, sütun + 1)==1)
                1'i döndür;
        }
       
        // Atanan numarasını kaldırıyoruz,
        // yaklaÅŸtıkça bu yana
        // yanlıştı ve bir sonraki adıma geçiyoruz
        // gelecek ile
        // fark sayıları deÄŸeri
        Ä±zgara[satır][sütun] = 0;
    }
    0 deÄŸeri döndürme;
}
 
int ana()
{
    // 0 atanmamış anlamına gelir gelir
    int ızgara[N][N] = { { 3, 0, 6, 5, 0, 8, 4, 0, 0 },
                       { 5, 2, 0, 0, 0, 0, 0, 0, 0 },
                       { 0, 8, 7, 0, 0, 0, 0, 3, 1 },
                       { 0, 0, 3, 0, 1, 0, 0, 8, 0 },
                       { 9, 0, 0, 8, 6, 3, 0, 0, 5 },
                       { 0, 5, 0, 0, 9, 0, 6, 0, 0 },
                       { 1, 3, 0, 0, 0, 0, 2, 5, 0 },
                       { 0, 0, 0, 0, 0, 0, 0, 7, 4 },
                       { 0, 0, 5, 2, 0, 6, 3, 0, 0 } };
 
    if (solveSudoku(ızgara, 0, 0)==1)
        yazdır(ızgara);
    baÅŸka
        printf("Çözüm yok");
 
    0 deÄŸeri döndürme;
    // Bu kod Pradeep Mondal P tarafından saÄŸlanmıştır
}
 
Sevgili arkadaşlar bu kodu abap'a çevirebilir misiniz?
 
 
8 REPLIES 8
Read only

Sandra_Rossi
Active Contributor
0 Likes
3,521

You have already asked people to give you ABAP code to solve Sudoku, you were given the algorithm, and now you are asking to convert C code to ABAP.

It should take a few hours to write ABAP from the algorithm (unless you are new to coding or to ABAP language).

What issue do you have with the algorithm or with the ABAP language?

Read only

0 Likes
3,497

I can't do it because I'm new to abap.

Read only

3,495

Then you shouldn't start with Sudoku solver.

Read only

abo
Active Contributor
3,398

You shouldn't try to translate C to ABAP when you're learning ABAP, just like you shouldn't try to translate your native language to English when you're learning English. Translation is a more complex task than simply writing in the new language.

Read only

Sandra_Rossi
Active Contributor
3,387

@Arslan1 

When you learn, you shouldn't ask others just to code the program for you.

Instead, you should learn by yourself, and ask a question only when you're stuck on a precise topic.

Read only

0 Likes
3,295

So you should first look at some Abap tutorial first ?

Read only

Ulrich_Schmidt1
Product and Topic Expert
Product and Topic Expert
0 Likes
3,281

What does this have to do with "ABAP Connectivity"?
"ABAP Connectivity" is about HTTP or RFC communication with an ABAP system. -- I don't see any network communication being used in the above example?!

Read only

0 Likes
3,259

Arslan1 has said "I'm new to abap" so I think it can be changed immediately to ABAP Development.