General discussion

Locked

please help me solve this program

By usamah18 ·
the program takse from the user any number between 0 - 32767 and displays it in a written form , then calcu;ates the sum of digits, and find the min and max numbers

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

please help me solve ths program

by obadare In reply to please help me solve this ...

try this: [java]
JTextField tf;
String input=tf.getText();
Integer[] ia=new Integer[input.length()];
int[] inta=new int[ia];
for(int i=0;i<ia.length;i++){
inta=ia.intvalue();
}
..so you now have an array of int which you can find sum,min,max.
I find it difficult to imagine the practical application of this though

Collapse -

an answer in c

by mmmova In reply to please help me solve this ...

/* a possible solution in tc3*/
*By MMM
*Hope this will solve your problem
*/

#include<stdio.h>
#include<conio.h>

void main()
{
int sum,min,max,numIn,num[],i=0;

printf("Enter a value between 0 and 32767: ");
scanf("%d, &num);//user input

//if invalid input....
//take input again
while(num<=0 || num>32767)
{
printf("Enter a value between 0 and 32767: ");
scanf("%d, &num);
}

while(num>0 && num<32767)
{
num=num%10;
sum+=num;
min=num[0];
max=num[0];
if(num<min)min=num;
if(num>max)max=num;
++i;
num/=10;

}
printf("The sum of %d digits is : ",i,sum);
printf("The max digit is : ",max);
printf("The min digit is : ",min);

getch();
}

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums