Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads in an integer that is greater than 1,000 and less tha

ID: 3645688 • Letter: W

Question

Write a program that reads in an integer that is greater than 1,000 and less than 1,000,000 . Recall that the number must be entered without a comma . Display the number with a comma inserted where it belongs .
( hint : use the % operator )

Explanation / Answer

int main() { char a[7]; int i=0,s,x; printf("enter the value"); scanf("%d",&s); if(s>=1000&&s0) { x=s%10; s=s/10; if((i==2)||(i==6)) /* in case of 1000,comma is inserted after 3 positions and after 7 positions in case of 1000000 */ { i++; a[i]=","; i++; } a[i]=x; i++; } for(i;i>=0;i--) { printf("%d ",a[i]); //printing the value after inserting comma(s) } } else return 0; return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote