I have two programs which gives a same output.....But they uses different logics....
So I want to compare their compilation and run time so I can understand which one is better....
The program gives an output like.....If u enter a number=789 then output=890 means each input digit got increament of 1
(1)
#include <stdio.h>
#include <conio.h>
#include <math.h>
main()
...{
int no, no1, no2, counter, ans;
ans=0;
counter=0;
printf("Enter any three digit number:");
scanf("%d" , &no );
while(no>0)
{
no1=no%10;
if(no1==9)
{
no2=0;
}
else
{
no2=no1+1;
}
ans=ans+(no2*pow(10,counter));
no=no/10;
counter=counter+1;
}
printf("ans is %d" , ans);
getch();
return 0;
}
(2)
#include <stdio.h>
int main()
{
unsigned int num, out=0, weight=1;
printf("Enter a number: ");
scanf("%u", &num);
while ( num > 0 )
{
out = out + ((((num % 10) + 1) % 10) * weight);
num = num / 10;
weight = weight * 10;
}
printf("%u\n", out);
return 0;
}