Formatted Numbers

//where is the problem

#include <iostream>

using namespace std;
long long int b[3],k=-1;
void revers(long long int a){
    if(a==0){
        return;
    }

revers(a/1000);
	k++;
	b[k]=a%1000;

}
int main() {
	long long int A;
	cin >> A;

	revers(A);
	for(int i=0;i<3;i++){

        cout<<b[i];
        if(i!=2){
            cout<<",";
        }
	}
}

@ekramhossain What if the number of digits in A is less than 7. I mean your code doesn’t give the correct answer if A < 1000000.

@hjr265 , Actually when I looked at the earliest solution, I found that it has a bug. If you input 0, it’ll output " 0, "
I don’t know how but this logic had been passed.

#include <stdio.h>
int main (){
int a,b,c,d,e;
scanf("%d",&a);
b=a/1000000;
c=a/1000;
d=c%1000;
e=a%1000;
printf("%d,%.3d,%.3d",b,d,e);
return 0;
}

whats wrong with this code

a = input()
r = ''
count = 0
for i in a[::-1]:
    r += i
    count += 1
    if count == 3 and len(a) != 3:
        count = 0
        r += ','
print(r[::-1])

Not understanding why my code is failing the test

@user.829677 Your code prints leading comma if a has 6 digits.

I hope this will help a lot…

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector vi;
typedef deque di;
typedef pair<ll,ll> pi;
#define pb push_back
#define mp make_pair
#define mh make_heap
#define pf push_front
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define INF 1000000000
#define FOR(i,a,b) for(ll i=a;i<b;i++)
const ll mod=1e9+7;

int main()
{
//freopen(“contest.txt”,“r”,stdin);
//freopen(“contest.txt”,“w”,stdout);
IOS
string s;
vi pos;
cin>>s;
for(ll i=s.size()-1;i>=0; i=i-3)
{
pos.pb(i);
}
sort(pos.begin(),pos.end()); pos.pop_back();
sort(pos.rbegin(),pos.rend());
for(ll i=0; i<s.size() ; i++)
{
if(!pos.empty()){
if(i==pos[pos.size()-1])
{
cout<<s[i]<<",";
pos.pop_back();

    }
    else
        cout<<s[i];


    }
    else
        cout<<s[i];


}


return 0;

}

Would you please explain me the error here ?

# include <stdio.h>
char n[10] ;

int len (char ara [])
{
    int i;
    for (i = 1; ara[i] != '\0'; i ++);
    return i;
}

int main ()
{
    scanf ("%s", &n);
    int i = len (n);
    int j = i%3;
    int k;
    for (k = 0; k < i; k ++){
        
        printf ("%c", n [k]);
        
        if (k == (j-1)){
            
            if (j == i){
                return 0;
            }
            
            printf (",");
            j++;
            j++;
            j++;
        }
        
    }
    return 0;
}

A = int(input())
num = “{:,}”.format(A)
print(num)

try this one

Why i am getting output error!!

#include <stdio.h>
int main()
{
long int n;
int k1,k2,k3;
scanf("%ld",&n);
if(n<=999)
{
printf("%ld\n",n);
}
else if(n<=999999)
{
k1=n%1000;
k2=n/1000;
printf("%d,%d",k2,k1);
}
else if(n<=2000000000){
k1=n%1000;
k2=n%1000000;
k2=k2/1000;
k3=n/1000000;
printf("%d,%d,%d",k3,k2,k1);
}
return 0;

 }

haha! lol,
you guys are so confused!
here my code is:

[REDACTED]

that’s it!
nothing else!!