63
#include<stdio.h> #include<conio.h> main() { int n,max=0,rem; printf("\n enter a number"); scanf("%d",&n); while(n!=0) { rem=n%10; n=n/10; if(rem>max) { max=rem: }} printf("\n the largest digit is: %d",max); getch(); }
int max = a>b?a:b; // set max to the larger of a and b
it was invented in 1950 when a Australian man Max Carter invented it because he wanted to make sense with direct numbers
Leaving aside the brute force method of trying all the number, The following is one way of reducing the number of possible solutions. You can elect, at any stage, to quit this process and try out each of the remaining possibilities. Max's number is odd. so it must be one of 43, 45, 47, 49, 51, 53, 57, 59, 61, 63. The difference between the digits is the same as the units digit which is odd. If the tens digit is 5, then the difference between 5 and the odd units digit would be even. That means the tens digit cannot be 5. Which leaves the following as possible solutions: 43, 45, 47, 49, 61, 63. Now, the tens digit is 4 or 6. The units digit must be between 1 and 9 (it is odd). so the difference between the tens and units digit must be 5 or fewer ie not 7 or 9. Then, since the difference is the same as the units digit, the units digit cannot be 7 or 9. So that leaves 43, 45, 61, 63. Now 43 an 45 both result in a difference of 1, not the units digit so neither can be a solution. That leaves 61 and 63. 61 has a digital difference of 5, not the units vaue which is 1. So 1 is not a possible answer and that leaves only 63. 6-3 = 3 so the difference is the same as the units digit. And that, my friend, is the answer - at long last!
max[x*y | x and y belong to {0,1,2,3,4,5,6,7,8,9}]
63
#include<stdio.h> #include<conio.h> void main() { int z,i,max=0; clrscr(); for(i=1;i<=5;i++) //change the digit 5 to anything { printf("Enter a number":); scanf("%d",&z); if(z>max) max=z; } printf("Largest number is=%d"z); getch(); }
#include#includevoid main(){long int n,r,m,max=0,count=0;clrscr();printf("Enter the Number:");scanf("%ld",&n);m=n;while(n>0){r=n%10;if(r>max)max=r;n=n/10;}printf("\nLargest Digit is = %ld",max);while(m>0){r=m%10;if(r==max)count++;m=m/10;}printf("\n\nOccurence of Largest Digit %ld is = %ld",max,count);getch();}output:Enter the Number:68596999Largest Digit is = 9Occurence of Largest Digit 9 is = 4
Max = 0For K = 1 to NIf Number(K) > Max then Max = Number(K)Next KPrint Max
#include<stdio.h> #include<conio.h> main() { int n,max=0,rem; printf("\n enter a number"); scanf("%d",&n); while(n!=0) { rem=n%10; n=n/10; if(rem>max) { max=rem: }} printf("\n the largest digit is: %d",max); getch(); }
19
The largest 3-digit prime number must be less than 1000, so work backwards from there. #include<iostream> #include<cmath> bool is_prime (const unsigned); // forward declaration int main () { unsigned n = 1000; while (!is_prime(--n)); std::cout << "The largest 3-digit prime is " << n << std::endl; } bool is_prime (const unsigned num) { if (num<2) return false; if (!(num%2)) return num==2; unsigned max = (unsigned) std::sqrt (num) + 1; for (unsigned div=3; div<max; ++div) if (!(num%div)) return false; return true; }
int max = a>b?a:b; // set max to the larger of a and b
max=number min=number counter=1 start while(counter<=3) read number start if max<number max=number else if min>number min=number end while write max write min /*modify the counter switch according to the number of values being compared if required*/
WikiAnswers does not give out personal information such as phone numbers.
#include<stdio.h> #include<conio.h> void main() { int a[4],max,i; clrscr(); printf("Enter the four numbers:\n"); for(i=0;i<4;i++) scanf("%d",a[i]); max=a[o]; for(i=1;i<4;i++) { if(a[i]>max) { max=a[i]; } } printf("The Greatest number is %d",max); getch(); }