Исправить ошибку: error C4700: использована неинициализированная локальная переменная "n" - C (СИ)
Формулировка задачи:
перевожу с С++ на Си такой код:
Код С++:
код Си:
и виводит ошибку:
Ошибка 1 error C4700: использована неинициализированная локальная переменная "n"
#include "stdafx.h"
#include <iostream>
using namespace std;
int countN(int count_of_monets);
int main() {
//cout<<"Введите количество монет"<<endl;
cout<<"Input numbers of monets "<<endl;
int n;
cin>>n;
int count=0;
cout<<countN(n)<<endl;
return 0;
}
int countN(int count_of_monets)
{
if(count_of_monets==0) return count_of_monets;
else if(count_of_monets<=3) return 1;
else if(count_of_monets%3!=0) return 1+countN(count_of_monets/3+1);
else return 1+countN(count_of_monets/3);
}#include "stdafx.h"
#include <stdio.h>
#include <iostream>
using namespace std;
int kilkistN(int kilkist_of_monets);
int main() {
//cout<<"Введите количество монет"<<endl;
printf("Введіть кількість монет:\n");
int n;
printf( "n");
scanf_s("n");
int kilkist = 0;
cout << kilkistN(n) << endl;
return 0;
}
int kilkistN(int kilkist_of_monets)
{
if (kilkist_of_monets == 0) return kilkist_of_monets;
else if (kilkist_of_monets <= 3) return 1;
else if (kilkist_of_monets % 3 != 0) return 1 + kilkistN(kilkist_of_monets / 3 + 1);
else return 1 + kilkistN(kilkist_of_monets / 3);
}Решение задачи: «Исправить ошибку: error C4700: использована неинициализированная локальная переменная "n"»
textual
Листинг программы
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
int kilkistN(int kilkist_of_monets);
int main() {
printf("Введіть кількість монет:\n");
int n;
scanf_s("%d", &n);
printf("%d\n",kilkistN(n));
return 0;
}
int kilkistN(int kilkist_of_monets){
if (kilkist_of_monets == 0) return kilkist_of_monets;
else if (kilkist_of_monets <= 3) return 1;
else if (kilkist_of_monets % 3 != 0) return 1 + kilkistN(kilkist_of_monets / 3 + 1);
else return 1 + kilkistN(kilkist_of_monets / 3);
}