Jump to content
Fórum Script Brasil
  • 0

Converter C++ para C


WellingtonCaldeira
 Share

Question

Olá pessoal preciso de uma ajuda para converter para Linguagem C... Toda vez que faço da erro

 

1º 

#include <iostream>


using namespace std;

int main(int argc, char const *argv[])
{
    int n;

    while(cin >> n && n)
    {
        int nc[n + 1];
        nc[n] = 1; nc[n - 1] = 1;

        for (int k = n - 2; k >= 0; --k)
            nc[k] = nc[k + 1] + nc[k + 2];

        cout << nc[0] << '\n';
    }
    return 0;
}

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>

#define sc3(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define for(i,a,n) for(int (i) = (a); (i) < (n); (i)++)

bool clap(int n);

int main(void)
{
    int n, m, k, p, curr, s;

    while(sc3(n,m,k) && (n || m || k))
    {
        p = s = 1;
        curr = 0;

        while(1)
        {
            curr++;

            if(p == m && clap(curr)){
                k--;
                if(k == 0){
                    printf("%d\n", curr);
                    break;
                }
            }

            p += s;

            if (p > n) {
                p = n - 1;
                s = -1;
            } else if (p == 0){
                p = 2;
                s = 1;
            }
        }
    }

    return 0;
}

bool clap(int n) 
{
    if(n % 7 == 0)
        return true;

    while (n) 
    {
        int r = n % 10;
        n /= 10;

        if (r == 7)
            return true;
    }

    return false;
}

 

 

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
string dec2hex( int n){
string chars = "0123456789ABCDEF";

int i = n % 16;

 if (n / 16 > 0) return dec2hex(n / 16) + chars.at(i);
string result = "";
 result += chars.at(i);
  return result;
}

int hex2dec(string h){
int dec = 0, base = 1;
int index = h.length();
string chars = "0123456789abcdef";

while (index--){
dec += chars.find_first_of(h.at(index)) * base;
base *= 16;
}

return dec;
}

int main() {
string n;

while (cin >> n && n != "-1"){
 if (n.size() >= 2 && n.at(1) == 'x'){
transform(n.begin(), n.end(), n.begin(), ::tolower);
printf (hex2dec(n.substr(2)) )endl;
} else {
cout << "0x" << dec2hex(atoi(n.c_str())) << endl;
}
}
return 0;
}

 

 

Obrigado!

Edited by WellingtonCaldeira
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      149.9k
    • Total Posts
      646.8k
×
×
  • Create New...