Computer Science, asked by Aishwarya98, 1 year ago

Write a 'C' program to arrange the even digits first and odd digits second of the given number vice versa.

Input Format

First input is option and next the value If the option is 0 - odd digits first 1 - even digits first

Constraints

1 ≤ num ≤ 100000007

Output Format

print the value

Sample Input 0

0 89745
Sample Output 0

97584

Answers

Answered by Shubhendu8898
21
hope you understand..........
Attachments:

Aishwarya98: thanks..
Aishwarya98: but..not using array..
Shubhendu8898: here is used array so thst it will be essy to program .. without array we have use loops like if,while, and have to difine a label where program comee after each input to check whether it is odd or even ..
Shubhendu8898: it will make program more complicated....
Aishwarya98: i want that answer (without using array)
Aishwarya98: if you know,please answer
Shubhendu8898: ok ..i will try it on my computer...but i never thinked it without array...
Aishwarya98: I hereby mark you as brainliest because you have answered somewhat relevant to the given question..
Shubhendu8898: oh!!thanks
Aishwarya98: this has helped me a lot..
Answered by tiger009
7

This program segment given below uses a straight-forward approach to count the number of odd and even digits in a given integer number (number).

Initially, variables n odd and n even, the counts for odd and even digits, respectively, are initialized to zero. Then a while loop is used to count the odd and even digits. In each iteration of this loop, the least significant digit of number number is first determined in variable digit,then the appropriate counter is incremented using an if-else statement and the least significant digit is removed from number number. The loop is executed as long as the value of number is greater than zero, i. e., all digits in number are not processed. Finally, the values of n odd and never are printed.

#include <stdio.h>

void main()

{    

      int n odd, n even, num,digit ;  

      clr scr ();

 

      print f("Count number of odd and even digits in a given integer number ");

      scan f("%d",& num);

               n odd = n even =0; /* count of odd and even digits */

               while ( num> 0)

                   {

                       digit = num % 10; /* separate LS digit from number */

                       if (digit % 2 == 1)

                          nodd++;

                       else n even++;

                              num /= 10; /* remove LS digit from num */

                   }

                       print f("Odd digits : %d Even digits: %d\n", n odd, n even);

                       getch (); }

Similar questions