+ 1
Where did i go wrong
for some reason when it finishes one time and person enters 1(to check again) it doesn't ask for a string(or number) it just finishes on its own!!(run the code in some other compiler if it doesn't run here) https://code.sololearn.com/cdxTkFa1EDQN/?ref=app
10 ответов
+ 1
hi,
use scanf("%s",a); // instead of gets(a);
this is making a infinite loop inside the code/program.
rest everything is fine.
+ 1
https://code.sololearn.com/c09ReIc0umaZ/?ref=app
try run it in your pc
+ 1
hi,
hello sayeef,
i have refreshed the code:
this is working.
pleas try this.
---------------------------------------
//A number is called a spy number, if the sum and product of its digits are equal.
#include<stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
c:
char a[20];
int d,b,mul=1,add=0;
printf("Please enter a number to check if it's a spy number or not:\n\nNumber:");
scanf("%s",a);
printf("\nmultiplication:");
for(d=0; d!=strlen(a); d++)
{
mul=mul*(a[d]-'0');
}
printf("%d\n\n", mul);
printf("addition:");
for(d=0; d!=strlen(a); d++)
{
add=add+(a[d]-'0');
}
printf("%d\n\n", add);
if(add==mul) {
printf("Because the sum and the product of the digits are equal, the number is a spy number.");
}
else
printf("Because the sum and the product of the digits are not equal, the number is not a spy number.");
printf("\n\nenter 1 to check again and enter 2 to exit");
scanf("%d", &b);
switch(b){
case 1: goto c;
case 2: break;
}
}
+ 1
hi, @sayeef
till i know;
-------------
1) there is some clash in the class of the main and stdio.h
with the string operations performed in the class.
///// Or /////
2) errors between a c functions used and c++ functions used
at the same time in a program
///// Or/////
3) functions not defined correctly.
So, try to define a separate function , in the main class for multiplication and addition.
do not make loops like while , for ( more than 1 loops ) inside
the main class //( this could produce an infinite loop)
// and the program would not terminate correctly.
// #C++ #Programming #Codding
0
its not work in sololearn..
but it must be work of complie sure
i means in computer or lap
0
run it in some other compiler, you'll understand what's going wrong(and i don't understand why)@arun tomar
0
okkkk
0
Sayeef
i already do it..
there is no problem
but you did a little mistake..
you define literal at the top
in c we define variable from the start..
0
i need to know what that is
0
thanks you @Rajeeb for clearing it up, can you explain why it does that? I don't really know about those