Application Development 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: 

Converting C Code to Abap

Arslan1
Explorer
0 Kudos
#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

Sandra_Rossi
Active Contributor
0 Kudos

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?

0 Kudos

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

Then you shouldn't start with Sudoku solver.

abo
Active Contributor

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.

Sandra_Rossi
Active Contributor

@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.

0 Kudos

So you should first look at some Abap tutorial first ?

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

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?!

0 Kudos

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