/*Program to find Sum of two numbers without using arithmetic operators*/

Source code:
#include<stdio.h>
void main()
 {
  int a,b;
  printf("Enter values for a,b\n");
  scanf("%d%d",&a,&b);
  while(a!=0&&b!=0)
   {
    a++;
    b--;
   }
  printf("Sum of two numbers=%d",a);
 }

Output:
Enter values for a,b
12
9
Sum of two numbers=21

******************************************************************

/*Program to find sum of individual digits of a given integer number*/

Source code:
#include<stdio.h>
void main()
 {
  int n,sum=0,digit;
  printf("Enter value for n\n");
  scanf("%d",&n);
  while(n!=0)
   {
    digit=n%10;
    sum=sum+digit;
    n=n/10;
   }
  printf("Sum of individual digits=%d",sum);
 }

Output:
Enter value for n
142
Sum of individual digits=7

******************************************************************

No comments:

Post a Comment