473,394 Members | 1,721 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,394 software developers and data experts.

pls help me banfa

an integer is divisible by 11 if the sum of the digits in odd position
equates to the sum of the digits in even position of the integer.Write
a program in C to find whether a given integer is divisible by 11
following the above rule.
Nov 8 '06 #1
3 1219
sicarie
4,677 Expert Mod 4TB
an integer is divisible by 11 if the sum of the digits in odd position
equates to the sum of the digits in even position of the integer.Write
a program in C to find whether a given integer is divisible by 11
following the above rule.
Where are you having trouble?
Nov 8 '06 #2
my trouble is i donot construct this program?
Nov 9 '06 #3
sivadhas2006
142 100+
Hi,

This may be help your need.
This is one way to implement your logic.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. int main(int argc, char* argv[])
  7. {
  8.    int
  9.       nInput = 0,
  10.       nIndex = 0,
  11.       nInputLength = 0,
  12.       nOddDigitsTotal = 0,
  13.       nEvenDigitsTotal = 0;      
  14.    char
  15.       szTemp[2],
  16.       szInput[10];
  17.  
  18.    // Get the input.
  19.    cout << "Enter the number : ";
  20.    cin >> nInput;
  21.  
  22.    // Convert to string.
  23.    itoa(nInput, szInput, 10);
  24.  
  25.    // Get the length of the string.
  26.    nInputLength = strlen(szInput);
  27.    szTemp[1] = 0;
  28.    for(nIndex = 0; nIndex < nInputLength; nIndex++)
  29.    {
  30.       szTemp[0] = szInput[nIndex];
  31.       if(nIndex % 2 == 1)
  32.       {         
  33.          nOddDigitsTotal = nOddDigitsTotal + atoi(szTemp);
  34.       }
  35.       else
  36.       {
  37.          nEvenDigitsTotal = nEvenDigitsTotal + atoi(szTemp);
  38.       }      
  39.    }
  40.  
  41.    // Check whether the odd digits total is e
  42.    if(nOddDigitsTotal == nEvenDigitsTotal)
  43.    {
  44.       cout << "The " << nInput << " is divisible by 11.";
  45.    }
  46.    else
  47.    {
  48.       cout << "The " << nInput << " is not divisible by 11.";
  49.    }   
  50.    return 0;
  51. }
  52.  
  53.  
  54.  
Regards,
M.Sivadhas.
Nov 9 '06 #4

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

Similar topics

8
by: RomanRusso | last post by:
Hie everybody, Here at this forum I have found something what I was looking for - rotation of cells in html table, here is the link http://www.thescripts.com/forum/threadnav149304-2-10.html The...
2
by: TanBrae | last post by:
Hi all. I found this forum while searching for an answer to an error message I am getting from my submission form on my website. I hope somebody will be able to help me with this. A bit of...
3
by: candexis | last post by:
Hi, I will like to know how can implement the rotation operand, I mean if I want shift a bit, the bit shifted (less significant bit) must put on the most significant bit, so this is a rotatioanl...
9
by: candexis | last post by:
Hi!!!!!!!!!!!!!!!!!!!! Please I want to know how to create a variable of 64 bits, and this variable must allow functionality for their shifting. Thanks for your help Best Regards,
2
by: anupam | last post by:
SOMEONE PLEASE GIVE SOME FREE LINK OR E-BOOK on MFC ...............
6
Niheel
by: Niheel | last post by:
I would like to honor Banfa with the Top Contributor Award. A little about Banfa: Banfa, or those of you who know him by his real name (Ben) has been a member of the community for a long...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.