Follow

Follow

Answered

The highest 3-digit number is 999. It's the 999th counting number. The first 99 counting numbers have fewer than 3 digits. So there are (999 - 99) = 900 positi…ve 3-digit numbers. The first is 100, the last is 999. 100 + 999 = 1,099 101 + 998 = 1,099 102 + 997 = 1,099 . . . There are (900/2) = 450 pairs; each pair adds up to 1,099. The sum of all pairs is (450 x 1,099) = 494,550 . (MORE)

Answered

In Technology

include<stdio.h> int main(){ int d,j=1,i,flag=0,count=0,k=0; int b[]; char a[],c; printf("enter the number="); scanf("%s",a); printf("enter the digit="); scanf("%c",&…;c); printf("the place value of given digit is:"); for(i=0;a[i]!='\\0';i++) { if(a[i]c) { b[k]a[i]-'0'; b[k]=b[k]=*j; flag=1; count++; k++; } j=j*10;}if(flag==1){ printf("the place value of given digit %c is:",c);for(i=0;i<count;i++)printf("\\n%d",b[i]);}elseprintf("your entered digit is not present in number");return 0;} (MORE)

Answered

include<stdio.h>#include<conio.h>void main(void){int num, a, b, sum;printf(""Please enter a four digit number: "");scanf("%d", &num);a=num/1000; // retrives th…e first digit(left most digit)b=num%10; //retrieves the fourth digit(right most digit)sum=a+b;printf("The sum of first and last digit is %d", sum);} (MORE)

Answered

include <stdio.h> int digit_sum(int); int digit_sum_rec(int); main() { int num; printf("Enter 5 digit positive integer. : "); scanf("%d",&num); printf("The s…um of the digits is: %d\\n",digit_sum(num)); printf("The sum of the digits is (calculated recursively): %d\\n", digit_sum_rec(num)); } int digit_sum(int n) { int t=0; while(n) { t+=n%10; n/=10; } return t; } int digit_sum_rec(int n) { if(n==0) return 0; return (n%10)+digit_sum_rec(n/10); } (MORE)

Answered

In Technology

int sumDigits(int n) { int sum = 0; while( n > 0 ) { sum += (n % 10); // add last digit of n to sum n /= 10; // divide n by 10 to "chop off" the last… digit } return sum; } ____________________________________________________ C program to find the sum of entered digit: By Jatinder Pal Singh #include<stdio.h>#include<conio.h>void main(){clrscr();int n,num,x,sum=0;printf("Enter a number=");scanf("%d",&n);while(n>0){x=n%10;sum=sum+x;n=n/10;}printf("Sum of digits of a number=%d",sum);getch();} (MORE)

A spreadsheet in Excel is comprised of a grid of cells. Each cell (which is defined as the intersection between a row and a column) can be allocated its own attributes. This i…s how cells are formatted. The most important attribute for any cell is the number type. This attribute (MORE)

In Craft Tips

Your preschool-aged child is at a point in his or her young life when learning is incredibly fun and entertaining. Even though attention spans are very short, their ability to… learn new concepts is quick. You can foster further learning and early math skills by creating experiences surrounding counting and (MORE)

In Bible

The book of Numbers is the fourth book in the Bible. It chronicles the history of the Hebrew people, following the giving of the Ten Commandments to Moses at Mount Sinai. It i…s part of the Pentateuch and part of the Jewish Torah. As such, it is an important part (MORE)

In Bible

The Bible tells us that the Exodus of Israelites out of Egypt was one of the greatest epic adventures in history. Against impossible odds, but with the help of God, Hebrew peo…ple left Egypt and spent forty years wandering in the wilderness, before they reached their destination, the land of (MORE)

Answered

In Technology

//Reverse of the Number// Programme Written By Maulin Thaker Ahmedabad;#include<stdio.h>#include<conio.h>void main(){int a,b,c,d,e;clrscr();printf("Enter the Numbe…r to Find it's Reverse\\n");scanf("%d",&a);while(a!=0){b=a%10;c=a/10;printf("%d",b);a=c;}getch();} (MORE)

Answered

In Technology

include<stdio.h> void main() { int no,rem=0,sum=0,n; /*declaration*/ printf("Enter 2 digit number:"); scanf("%d",&no); for(n=1;n<3;n…++) /*conditions*/ { rem=no%10; /*separation of digits using % and / */ sum=sum+rem; no=no/10; } printf("sum=%d",sum); } (MORE)

Answered

In Technology

include <stdio.h> #include <conio.h> { unsigned long reverse(int); int n; clrscr(); Printf("reverse of a given no is:%lu",reverse(n)); getch(); } unsigned… long rev(int x); { unsigned long r=0; while(x>0) { r=r*10+(x/10); x=x/10; } return r; } (MORE)

Answered

Here You go........... # include<stdio.h># include<conio.h>void main(){int no,sum=0,rem=0;clrscr();printf("\\nEnter a Number: ");scanf("%d",&no);while(no>0)…{rem=no%10;sum=sum+rem;no=no/10;}printf("\\nSum of digits of a number: %d",sum);getch();} (MORE)

Answered

In Technology

There is a far easier way to implement the required functionality than using inheritance. However, to answer the question, here's one possible solution that makes use of inher…itance:#include<iostream>#include<iomanip>#include<random>#include<time.h>// In order to make use of inheritance we need a common base class.// Although the underlying datatype is an integral, we cannot inherit from an integral,// therefore we need to embed the integral in the base class, and provide operators// that allow the class to function as if it were an integral. Only the bare minimum// implementation required to achieve the goal is provided.class integral_t{friend std::ostream& operator<< (std::ostream&, const integral_t&);protected:unsigned m_number;public: integral_t (const unsigned number) : m_number (number) {} integral_t (const integral_t& object) : m_number (object.m_number) {}integral_t& operator/= (const unsigned number) { m_number /= number; return *this; }integral_t& operator%= (const unsigned number) { m_number %= number; return *this; }// Virtual conversion operator required to provide specialised functionality// for the output stream insertion operator (overloaded friend function).virtual operator unsigned () const { return m_number; } };// overloaded friend function to allow insertion into an output streamstd::ostream& operator<< (std::ostream& os, const integral_t& obj){// call virtual conversion operator to ensure most-specialised behaviour.os << (unsigned) obj;return os;}// The reverse class inherits from the integral base class, overloading the virtual// unsigned conversion operator to reverse the digits of the underlying integral.class reverse_t : public integral_t{public:reverse_t (const unsigned number) : integral_t (number) {}reverse_t (const integral_t& object) : integral_t (object) {}virtual operator unsigned () const { unsigned result = 0;unsigned number = m_number;do {result *= 10;result += number % 10;} while (number /= 10);return result;}};// The sum class inherits from the integral base class, overloading the virtual// unsigned conversion operator to sum the digits of the underlying integral.class sum_t : public integral_t{public:sum_t (const unsigned number) : integral_t (number) {}sum_t (const integral_t& object) : integral_t (object) {}virtual operator unsigned () const { unsigned result = 0;unsigned number = m_number;do {result += number % 10;} while (number /= 10);return result;}};// The main function exercises all three classes.int main(){using std::cout;using std::endl;using std::setw;// pseudo-random number generatorstd::default_random_engine generator;generator.seed ((unsigned) time (NULL));std::uniform_int_distribution<unsigned> distribution (1000, 9999);// generate ten 4-digit numbers at randomfor (unsigned count = 0; count < 10; ++count){// Instantiate an integral object.integral_t num = distribution (generator);// Instantiate a sum object from the integral.sum_t sum = num;// Instantiate a reverse object from the integral.reverse_t rev = num;// Print all three objects.cout << "Number:" << setw(5) << num << "\\tSum of digits: " << setw(3) << sum <<"\\tReversed digits: " << setw(5) << rev << endl;}} Example output:Number: 5746 Sum of digits: 22 Reversed digits: 6475Number: 8356 Sum of digits: 22 Reversed digits: 6538Number: 4307 Sum of digits: 14 Reversed digits: 7034Number: 8062 Sum of digits: 16 Reversed digits: 2608Number: 6162 Sum of digits: 15 Reversed digits: 2616Number: 1167 Sum of digits: 15 Reversed digits: 7611Number: 5025 Sum of digits: 12 Reversed digits: 5205Number: 4646 Sum of digits: 20 Reversed digits: 6464Number: 2962 Sum of digits: 19 Reversed digits: 2692Number: 1703 Sum of digits: 11 Reversed digits: 3071A far better solution would be to use two simple functions:unsigned sum_digits (unsigned number) { unsigned result = 0;do {result += number % 10;} while (number /= 10);return result;} unsigned reverse_digits (unsigned number) { unsigned result = 0;do {result *= 10;result += number % 10;} while (number /= 10);return result;} As you can see, the only difference between these two functions is that the reverse_digits function includes one additional statement, result *= 10;. Although inheritance is intended to avoid code duplication, if you examine the code carefully you will see that they are not in fact duplicates. They are entirely different algorithms because the difference is within an iterative loop, and it's just not possible to optimise away the difference without introducing unnecessary complexity and inefficiency.If you examine the classes again, you will find that both derivatives contain almost identical implementations to those shown above within each of their virtual conversion overloads, so inheritance offers no practical advantage over the functions. However, we've actually done far worse because we've introduced duplicate code that is already built-in to C++ itself! That is, the integral_t type is not providing any functionality that isn't already built-in (everything it does we can already achieve with a primitive unsigned int). The sole reason for having it was simply to enable an inheritance system that was never required in the first place.When writing programs, regardless of the language, we must always strive for the simplest solutions to every problem we encounter, using the most efficient algorithms available, or redesigning existing algorithms to make them more efficient. Adding layers of complexity unnecessarily is simply an exercise in futility -- and a complete waste of time (and money!). Just because it can be done, doesn't mean it should be done, not when there's a better, simpler, more efficient method already available. (MORE)