Given three positive integers as input from the user, display the three numbers
ID: 3684283 • Letter: G
Question
Given three positive integers as input from the user, display the three numbers as one concatenated (long long) integer, the total number of unique digits in the concatenated (long long) integer, and the middle digit, or digits when the total number of digits in the concatenated (long long) integer is even. All leading zero digits are to be discarded. No array use allowed. Given three positive integers as input from the user, display the three numbers as one concatenated (long long) integer, the total number of unique digits in the concatenated (long long) integer, and the middle digit, or digits when the total number of digits in the concatenated (long long) integer is even. All leading zero digits are to be discarded. No array use allowed. Given three positive integers as input from the user, display the three numbers as one concatenated (long long) integer, the total number of unique digits in the concatenated (long long) integer, and the middle digit, or digits when the total number of digits in the concatenated (long long) integer is even. All leading zero digits are to be discarded. No array use allowed.Explanation / Answer
#include <stdio.h>
#include <math.h>
int no_of_digit(long long int a)
{
int count = 0;
while(a!=0)
{
a = a/10;
count++;
}
return count;
}
int main()
{
int a,b,c;
int count, flag, r, len_concat, two_digit, one_digit, i;
scanf("%d", &a);
scanf(" %d", &b);
scanf(" %d", &c);
long long int concat, temp;
int len_b = no_of_digit(b);
int len_c = no_of_digit(c);
concat = a*pow(10,len_b+len_c) + b*pow(10,len_c) + c;
printf("Concated long long integer: %ld ", concat);
count = 0;
for(i=0;i<10;i++)
{
temp = concat;
flag = 0;
while(temp!=0)
{
r = temp%10;
if(r==i)
flag = 1;
temp/=10;
}
if(flag==1)
count++;
}
printf("No. of unique digits = %d ", count);
len_concat = no_of_digit(concat);
temp = concat;
r = 0;
if(len_concat%2==0)
{
while(r<(len_concat/2-1))
{
r++;
temp/=10;
}
two_digit = temp%100;
printf("Middle digits = %d ", two_digit);
}else
{
while(r<(len_concat/2))
{
r++;
temp/=10;
}
> printf("Middle digit = %d ", one_digit);
}
return 1;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.