0% found this document useful (0 votes)
4 views

Batch 5 IEEE

The document outlines algorithms and C programs for various tasks involving number manipulation, including rearranging digits in ascending and descending order, printing numbers in words, and handling input validation. It provides examples and logic for each task, demonstrating how to read numbers and format output accordingly. The content is structured into sections labeled as questions, detailing specific programming challenges and their solutions.

Uploaded by

velugotibhavya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Batch 5 IEEE

The document outlines algorithms and C programs for various tasks involving number manipulation, including rearranging digits in ascending and descending order, printing numbers in words, and handling input validation. It provides examples and logic for each task, demonstrating how to read numbers and format output accordingly. The content is structured into sections labeled as questions, detailing specific programming challenges and their solutions.

Uploaded by

velugotibhavya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

4.

if(n>0)
Batch number – 5
go to step 3
V.Bhavya-241FA04950
5. for (i=0; I < digit ;i++)
Sd.Bashu-241FA04949 6. print(digit)
V. SyamPrasad-241FA04939 7. stop
T.Deekshith-241FA04980
Question-7.B
Question-7.A 1. Ascending Order is arranging of numbers
“Printf statement is used to print desired from smallest value to largest value. Develop a
numbers or characters in C”. Develop an program to read an integer number with
algorithm that can read a number as input from minimum of 6 digits as input rearrange the
the keyboard and print a number with the digits of the number in ascending order.
repetition every digit, the digit number of times.  Examples:
 Examples: INPUT: 465128
INPUT: 12 OUTPUT: 124568
INPUT: 46 INPUT: 9447523657812 OUTPUT:
OUTPUT: 122 1223445567789
OUTPUT: 4444666666 Logic

Logic For (i = 0; i <= 9; i++) {

while(n>0) { temp = num

digit=n%10 while(temp > 0) {

n=n/10 digit = temp % 10

for (i=0; i < digit ;i++) { if (digit == i) {

print (digit) printf("%d", digit)

} Algorithm

} 1. Start

Algorithm 2.Read num

1.Start 3. for(i = 0; i <= 9; i++)

2. read n 4.temp = num

3. digit =n%10 5.digit = temp % 10

n=n/10 temp /= 10

6. if(temp>0)
go to step5 printf("\n");

7 .if (digit == i) }
8. print(digit)

Program

long int num, temp; Question-B


#include <stdio.h>
2. For the input taken in Question 1. b (1),
int main() { rearrange the number in descending order with
the implementation of Question 1. a in it. Take
int digit, i, j; the minimum number of digits to be 3 as
printf("Enter a number with at least 6 digits: "); input.
scanf("%ld", &num);  Examples:
for (i = 0; i <= 9; i++) { INPUT: 185 OUTPUT:
temp = num; 88888888555551

while (temp > 0) { INPUT: 236

digit = temp % 10; Output: 66666633322

if (digit == i) { Logic

printf("%d", digit); for(i = 9; i >= 0; i--) {

} temp = num

temp /= 10; while (temp > 0) {

} digit = temp % 10

} if (digit == i) {
print(digit) digit = temp % 10;

Algorithm if (digit == i) {

1. start printf("%d", digit);

2.read num }

3.for (i = 9; i >= 0; i--) }

4.temp = num temp /= 10;

5.digit = temp % 10 }

temp/=10 }

(6.if temp > 0) printf("\n");

go to step5 return 0;

6 .if (digit == i) }

7. print(digit)

8 .stop

Program

#include <stdio.h>

int main() {

long int num, temp;


Question-7.C
int digit, i, j;
i. “Playing with numbers is Fun”. For any
printf("Enter a number with at least 3 digits: "); number given as input develop a program to
scanf("%ld", &num); print the output as the number in words.

for(i = 9; i >= 0; i--) { Examples:

temp = num; INPUT: 124

while(temp > 0) { OUTPUT: ONE TWO FOUR


INPUT: 357 num /= 10

Output: THREE FIVE SEVEN 6.if(num>0)

Logic go to step6

switch(digit) { 7. if(num == 0)

case 0: printf("ZERO "); break; printDigitInWords (0)

case 1: printf("ONE "); break; 8. temp = reverseNumber (num)

case 2: printf("TWO "); break; 9.printDigitInWords(temp % 10)

case 3: printf("THREE "); break; temp /= 10

case 4: printf("FOUR "); break; 10.if(temp > 0)

case 5: printf("FIVE "); break; go to step9

case 6: printf("SIX "); break; 11.stop

case 7: printf("SEVEN "); break;

case 8: printf("EIGHT "); break;

case 9: printf("NINE "); break;

while (num > 0) {

reversed = reversed * 10 + num % 10;

num /= 10;

if (num == 0) {

printDigitInWords(0);

printf("\n");

Algorithm
1. Start

2. read digit

3. switch (digit)
Program
4. Enter cases
#include <stdio.h>
5. reversed = reversed * 10 + num % 10
int printDigitInWords(int digit) {
switch (digit) { }

case 0: printf("ZERO "); break; temp = reverseNumber(num);

case 1: printf("ONE "); break; while (temp > 0) {

case 2: printf("TWO "); break; printDigitInWords(temp % 10);

case 3: printf("THREE "); break; temp /= 10;

case 4: printf("FOUR "); break; }

case 5: printf("FIVE "); break; printf("\n");

case 6: printf("SIX "); break; }

case 7: printf("SEVEN "); break;

case 8: printf("EIGHT "); break;

case 9: printf("NINE "); break;

int reverseNumber(int num) {

int reversed = 0;

while (num > 0) {

reversed = reversed * 10 + num % 10;

num /= 10;

}
Question-7.C
return reversed;
ii. For the input taken in Question 1. C (i), the
} number can also be written based on their place
in the digits value. Develop a program to
int main() {
rewrite the number in words based on their
int num, temp; place value.

printf("Enter a number: "); INPUT: 124

scanf("%d", &num); OUTPUT: ONE HUNDRED TWENTY FOUR

if (num == 0) { Logic

printDigitInWords(0);  if (num == 1)

printf("\n");  printf("ONE")

return 0;  else if (num == 2)


 printf("TWO")  printf("SIXTEEN")

 else if (num == 3)  else if (num == 17)

 printf("THREE")  printf("SEVENTEEN")

 else if (num == 4)  else if (num == 18)

 printf("FOUR")  printf("EIGHTEEN")

 else if (num == 5)  if (ones != 0) {

 printf("FIVE")  printf(" ")

 else if (num == 6) Algorithm

 printf("SIX") 1.start

 else if (num == 7) 2. Read digit

 printf("SEVEN") 3. if(num == 1)

 else if (num == 8) print(ONE)

 printf("EIGHT") else if (num == 2)

 else if (num == 9)

 printf("NINE") (TWO)

else if (num < 20) { else if (num == 3)

 if (num == 10) print(THREE)

 printf("TEN") else if (num == 4)

 else if (num == 11) print(FOUR)

 printf("ELEVEN") else if (num == 5)

 else if (num == 12) print(FIVE)

 printf("TWELVE") else if (num == 6)

 else if (num == 13) print(SIX)

 printf("THIRTEEN") else if (num == 7)

 else if (num == 14) print(SEVEN)

 printf("FOURTEEN") else if (num == 8)

 else if (num == 15) print(EIGHT)

 printf("FIFTEEN") else if (num == 9)

 else if (num == 16) print(NINE)


4. if (num < 10)

 print_single_digit(num)

 else if (num < 20)

 if (num == 10)

 print("TEN")

 else if (num == 11)

 print("ELEVEN");

 else if (num == 12)

 print("TWELVE")

 else if (num == 13)

 print("THIRTEEN")

 else if (num == 14)

 print("FOURTEEN")

 else if (num == 15)

 print("FIFTEEN")

 else if (num == 16)

 print("SIXTEEN")

 else if (num == 17)

 print("SEVENTEEN")

 else if (num == 18)

 print("EIGHTEEN")

 5. else if(ones != 0)

print_single_digit(ones)

 6. else (num == 0)

print(ZERO)

 7.stop
 if (num < 10) {

 print_single_digit(num);

 }

 else if (num < 20) {

 if (num == 10)

Program  printf("TEN");

 #include <stdio.h>  else if (num == 11)

 int print_single_digit(int num) {  printf("ELEVEN");

 if (num == 1)  else if (num == 12)

 printf("ONE");  printf("TWELVE");

 else if (num == 2)  else if (num == 13)

 printf("TWO");  printf("THIRTEEN");

 else if (num == 3)  else if (num == 14)

 printf("THREE");  printf("FOURTEEN");

 else if (num == 4)  else if (num == 15)

 printf("FOUR");  printf("FIFTEEN");

 else if (num == 5)  else if (num == 16)

 printf("FIVE");  printf("SIXTEEN");

 else if (num == 6)  else if (num == 17)

 printf("SIX");  printf("SEVENTEEN");

 else if (num == 7)  else if (num == 18)

 printf("SEVEN");  printf("EIGHTEEN");

 else if (num == 8)  else if (num == 19)

 printf("EIGHT");  printf("NINETEEN");

 else if (num == 9)  } else {

 printf("NINE");  int tens = num / 10;

 }  if (tens == 2) printf("TWENTY");

 int print_two_digits(int num) {  else if (tens == 3) printf("THIRTY");


 else if (tens == 4) printf("FORTY");  print_two_digits(num);

 else if (tens == 5) printf("FIFTY");  }

 else if (tens == 6) printf("SIXTY");  printf("\n");

 else if (tens == 7)  }
printf("SEVENTY");
 int main() {
 else if (tens == 8) printf("EIGHTY");
 int number;
 else if (tens == 9) printf("NINETY");
 printf("Enter a number: ");
 int ones = num % 10;
 scanf("%d", &number);
 if (ones != 0) {
 print_number_in_words(number);
 printf(" ");
 }
 print_single_digit(ones);

 }

 }

 }

 void print_number_in_words(int num) {

 if (num == 0) {

 printf("ZERO\n");

 return;

 }

 if (num >= 100) {

 int hundreds = num / 100;

 print_single_digit(hundreds);

 printf(" HUNDRED");

 num %= 100;

 if (num != 0) {

 printf(" ");

 }

 }

 if (num > 0) {
THANK YOU

You might also like