- Related Questions & Answers
- C Program for Tower of Hanoi
- C++ Program for Dijkstra’s shortest path algorithm?
- C/C++ Program for nth Catalan Number?
- C Program to Multiply two Floating Point Numbers?
- C program to find the length of a string?
- C Program to Check if all digits of a number divide it
- C Program to Check if a Given String is a Palindrome?
- Write a program to Delete a Tree in C programming
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Sums of ASCII values of each word in a sentence in c programming
- Sum of the nodes of a Singly Linked List in C Program
- Sum of first n natural numbers in C Program
- C Program for simple interest?
- Area of a n-sided regular polygon with given Radius in C Program?
- Area of a leaf inside a square in C Program?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have one long integer. We have to find if the differences between the sum of the odd position digits, and the sum of the even position digits are 0 or not. The positions are start from 0 (left most).

For example, suppose a number is 156486. The odd position sum is (5 + 4 + 6) = 15, and even position sum is (1 + 6 + 8) = 15, so they are same.

To solve this problem, we can use two different ways. The first way is traversing form start to end and get the sum by alternating the position, then get the difference. The next method is simpler, and efficient. If the number is divisible by 11, then the difference must be 0. So in other words we can say that if the sum of odd position numbers and sum of even position numbers are same, then the number is divisible by 11.

begin if n is divisible by 11, then return 1 else return 0 end if end

#include<stdio.h> long isDiffZero(int n) { if(n % 11 == 0){ return 1; } else { return 0; } } main() { int n; printf("Enter a number: "); scanf("%d", &n); if(isDiffZero(n)) { printf("Difference is zero"); } else { printf("Difference is non zero"); } }

Enter a number: 156486 Difference is zero

Advertisements