this simple code giving error ?

it's giring error, sorry for rules

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){
	int a= rand();
	int s=1;int i;int r;
	
	while((a%s)!=0){
	s=s*10;
	i++;
	}
	for(r=0;r<=i;r++){
		s=s/10;
		printf("%d",(a%s));
	}
		
	return 0;
}
Firstly you forgot to initialize your variable 'i'.
Secondly, what are you trying to do?

The condition you've written inside your while loop, (a%s) != 0) will always return false as a%s will always be 0 (because 1 perfectly divides every real number). 0 != 0 gives us false.

So i's value would be set to 0 and your second for-loop would never execute.
I'm not sure what you're trying to do, sorry. But I would suggest giving better identifiers to your variables.

Also that is C not C++.
thnks, i read every c is c++ so if you can show me c helping forum? i have new questions, thnk you again
Last edited on
Topic archived. No new replies allowed.