473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

I want a hlep to write this program

1-Write a program that prompts the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. For example, it should output the individual digits of 3456 as 3 4 5 6, output the individual digits of -2345 as 2 3 4 5.
I see this program in this site and no body reply it, am really need the solution of it because this question is in my assignment.
please help me?
Dec 3 '06 #1
2 2017
sala
12
first i want to tell that i wrote as you the problem without trying and i wait for the answer but anyone send me a reply, for that i learn to search the algorithm from the internet , so what i wrote below is just what i found in my search; if it is not enough you could search further, good luck ;-)

// Run through each single digit to create a new string. Even digits
// are multiplied by two, odd digits are left alone.

t = " ";
for (i = 0; i < r.length; i++) {
c = parseInt(r.charAt(i), 10);
if (i % 2 != 0)
c *= 2;
t = t + c;
}

// Finally, add up all the single digits in this string.

n = 0;
for (i = 0; i < t.length; i++) {
c = parseInt(t.charAt(i), 10);
n = n + c;
}

Once the sum is found, the code checks to see if it's an even multiple of ten (i.e., n % 10 leaves no remainder).

// If the resulting sum is an even multiple of ten (but not zero), the
// card number is good.

if (n != 0 && n % 10 == 0)
return true;
else
return false;
}
Dec 3 '06 #2
suganya
39
Try this.

void main()
{
unsigned int n,i=0,j=0;
char a[10],temp;
printf("\n Enter any positive integer value");
scanf("%d",&n);
do{
a[i++] = '0' + n%10;
n = n/10;
}while(n!=0);
a[i] = 0;
i--;
while(i>j)
{
temp = a[j];
a[j++] = a[i];
a[i--] = temp;
}
printf("\n The string is %s",a);
getch();
}
Dec 4 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: meyvn77 | last post by:
Im using an ADP to connect to a SQL Sqever DB. In access it was really easy to say Inner join on table1 and table2 and update columnA from table1 with columnC from table2 where table1.key =...
11
by: Michael B. | last post by:
I'm still learning C so I've written a simple app which lets you make a contact list (stored as a linked list of structs), write it to a file, and read it back. It works fine, but I notice in my...
1
by: flash | last post by:
Need hlep to delete array only because all function is ok (inser, sort andsearch) #include <iostream.h> //functions prototype void Insert(int,int); void Delete(int,int); int...
8
HaLo2FrEeEk
by: HaLo2FrEeEk | last post by:
I'd like to write a program to assist me in upoloading files to my site. I know how to upload the files using C#, I just don't know how to have an interface and still accept commandline parameters. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.