int nearPalin(int n){ int temp = n; int count = 0; while(temp>0){ temp /= 10; count++; } if(count%2 == 0){ count = count/2; while(count--) n = n / 10; temp = n; while(n>0){ temp = temp*10 + n%10; n = n/10; } return temp; } else{ count = count/2; while(count--) n = n / 10; temp = n; n = n/10; while(n>0){ temp = temp*10 + n%10; n = n/10; } return temp; } }
0
Mexico - 0 Peru - 0
void foo (unsigned int x) { static count {0}; ++count; if (x != 0) return foo (--x); return count; } int main() { int cnt = foo (10); assert (cnt==10); cnt = foo (5); assert (cnt==15); }
Repeatedly divide by the base until the number is 0, counting the number of divisions as you go. int count_digits (int n, int base=10) { // default to decimal notation if (base<2) {/* handle invalid argument */} int count=0; while (n!=0) { n/=base; ++count; } return count; } Note that the value 0 has no digits. If you wish to count 0 as a digit, alter the algorithm as follows: int count_digits (int n, int base=10) { // default to decimal notation if (base<2) {/* handle invalid argument */} int count=0; do { n/=base; ++count; } while (n!=0); return count; }
#include<stdio.h> #include<conio.h> void main() { int a[10],i,j,k; int count=1,num[10],pos=0; clrscr(); printf("Enter the Array Element "); for(i=0;i<10;i++) { scanf("%d",&a[i]) ; }//close the for loop for(i=0;i<10;i++) { count=1,pos++; for(j=0;j<10;j++) { if(a[i]==a[j]) { for(k=j;k<10;j++) a[k]=a[k+1] }//close the if count++; }//close the for loop num[pos] = count; }//close the for loop for(i=0;i<pos;i++) printf("Repeted Number of IN Arrary %d",num[i]); }//close the main
# include <stdio.h> main() { int num,count,sum; count=0; sum=0; printf("enter an integer :"); scanf("%d",&num); printf("ur num is : %d \n",num); while (num!=0) { count++; sum+=num%10; num/=10; } printf("sum of the digits is : %d",sum); }
in Peru when it is cold in England it is hot in Peru and when in Peru its cold in England it is hot
import java.util.Scanner; public class float_values{ private static double sum = 0, average = 0; public static void main(String[] args){ Scanner reader = new Scanner(System.in); double[] values = new double[10]; for (int count = 0; count < 10; count++){ System.out.println("Enter number " + (count + 1)); values[count] = reader.nextDouble(); } for ( int i = 0; i < values.length; i++){ sum += values[i]; } average = (sum / values.length); System.out.println("The sum of the numbers is " + sum); System.out.println("The average of the numbers is " + average); } }
12
10
10 All you have to do is count up by 10 because 5 can go into10