Answered Questions

  • Print Sum of Digits

    Write a function to print sum of the digits in a given integer n without converting it to String. For example : if n = 1234 the function should return 1+2+3+4 = 10 if n = 15 the function should return 1+5 =6 if n = 5 the function should return 5.

    sravani reddy

    • Sep 21st, 2017

    Code
    1. #include<stdio.h>
    2. int main()
    3. {
    4. int rem,sum=0,n;
    5. printf("enter the number:");
    6. scanf("%d
    7. ",&n);
    8. while(n!=0)
    9. {
    10. rem=n%10;
    11. sum=sum+rem;
    12. n=n/10;
    13. }
    14. printf("the sum of digits of a number is %d",sum);
    15. return 0;
    16. }

    Shasan

    • Mar 29th, 2016

    "c# public static int Sum() { int n = 1235678; int n1 = 0; int f = 0; while (n!= 0) { ...

  • case sensitive

    why the programing language are case sensitive as is not for user friendly.

    lavanyats

    • Jul 27th, 2008

    When a PL is case sensitive, the number of possible keywords/ variable names permissible is increased. Also - more important reason - program readability is improved - we use caps for macros, have different naming conventions based on case sensitivity and so on.

  • How to write Spiral matrix program?

    ashoknaina

    • Dec 20th, 2011

    Code
    1. #include<stdio.h>
    2. main()
    3. {
    4. int a[20][20],i,j,n,m,p,q,k=0;
    5. Enter Order Of matrix");
    6. scanf("%d%d",&m,&n);
    7. for(i=1;i<=m;i++)
    8. for(j=1;j<=n;j++)
    9.     scanf("%d",&a[i][j]);
    10.  
    11. p=m;
    12. q=n;
    13. i=j=1;
    14.  
    15. while(k<p*q)
    16. {
    17.     for(;j<=n&&k<p*q;j++)
    18.     {
    19.         printf("%d ",a[i][j]);
    20.         k++;
    21.     }
    22.     j--;  
    23.     i++;
    24.     for(;i<=m && k<p*q;i++)
    25.     {
    26.         printf("%d ",a[i][j]);
    27.         k++;
    28.     }
    29.     i--;
    30.     j--;    
    31.     for(;j>=i-m+1 && k<p*q;j--)
    32.     {
    33.         printf("%d ",a[i][j]);
    34.         k++;
    35.     }    
    36.     j++;
    37.     i--;
    38.     for(;i>1 && k<p*q;i--)
    39.     {
    40.         printf("%d ",a[i][j]);
    41.         k++;
    42.     }
    43.     if(k<p*q)
    44.     {
    45.         j++;
    46.         i++;
    47.         n--;
    48.         m--;
    49.     }
    50. }
    51. }