/*The coding style used in this source code is for convenience.
* It is widely used style of coding. */
#include <stdio.h>
void main() {
int number, modulus, reverse;
reverse = 0;
printf("Enter a number \n");
scanf("%d", &number);
while(number != 0) {
modulus = number % 10;
reverse = (reverse * 10) + modulus;
number =number / 10;
}
printf("The reversed number is %d", reverse);
getch();
}
int RevNum( int num )
{
const int base = 10;
int result = 0;
do
{
result *= base;
result += num % base;
} while( num /= base);
return( result );
}
There are two ways to reverse a number, as a string and as a value. The string form is required if you wish values with trailing zeroes to be written literally, so that 100 becomes 001. As a value, 100 becomes 1. Both forms are shown in the example below, which prints 10 random numbers in reverse.
#include<iostream>
#include<time.h>
int rev_as_num(int num)
{
int result = 0;
while( num )
{
result*=10;
result+=num%10;
num/=10;
}
return(result);
}
std::string rev_as_string(int num)
{
std::string result;
while( num )
{
result.push_back(num%10+'0');
num/=10;
}
return(result);
}
int main()
{
srand((unsigned) time(NULL));
for( int loop=0; loop<10; ++loop )
{
int num = rand(); // random number in range [0...RAND_MAX].
std::cout<<"Original:\t"<<num<<'\n'
<<"Reversed:\t"<<rev_as_string(num).c_str()<<'\n'
<<"As value:\t"<<rev_as_num(num)<<'\n'<<std::endl;
}
return(0);
}
Example output:
Original: 32254
Reversed: 45223
As value: 45223
Original: 15754
Reversed: 45751
As value: 45751
Original: 19691
Reversed: 19691
As value: 19691
Original: 10922
Reversed: 22901
As value: 22901
Original: 19449
Reversed: 94491
As value: 94491
Original: 24028
Reversed: 82042
As value: 82042
Original: 5746
Reversed: 6475
As value: 6475
Original: 29410
Reversed: 01492
As value: 1492
Original: 6189
Reversed: 9816
As value: 9816
Original: 20712
Reversed: 21702
As value: 21702
int RevNum( int num )
{
const int base = 10;
int result = 0;
int remain = 0;
do
{
remain = num % base;
result *= base;
result += remain;
} while( num /= base);
return( result );
}
Generic programming means that the code is generic enough that it compile on any C++ implementation. That is, it has no platform-specific code.
Turbo C is a compiler for a general purpose computer programming language called C. It transforms code written in C into the computer language needed for executable programming.
i cant sorry
A C program is a computer program written using the C programming language.
PHP and C are two different programming languages that cannot directly interact with eachother. You can have a program made with C call a PHP script, using its output (an indirect interaction), but there's no way to "embed" PHP into C code.
code for creating pascal's triangle in C programming language?
C is a programming language, so it doesn't have source code.(On the other hand, C compilers do have source code, but you, as a beginner in programming, could not understand them.)
sense question Your makes no.
You can find C programming tutorials online at the C programming website. They provide both free and paid tutorials for many aspects of the C and C++ code.
Generic programming means that the code is generic enough that it compile on any C++ implementation. That is, it has no platform-specific code.
C is a programming language, and it's mostly used for Systems Programming. Most kernels these days have at least some C code in them.
C++
Here is the article for Mouse programming in C. In this link full details are given nicely.http://electrofriends.com/articles/computer-science/c-tutorials/mouse-programming-in-cc/
Programming in C++ means designing and writing a computer program using the C++ programming language. C++ is a high-level, machine-independent language which must be converted into machine-dependent code by a compiler.
Turbo C is a compiler for a general purpose computer programming language called C. It transforms code written in C into the computer language needed for executable programming.
i cant sorry
A C program is a computer program written using the C programming language.