C Program to print day using the sum of Number
This C program finds the sum of individual digits in a number and applies modular function to provide output as day ie:if sum of digits is 3 it prints Tuesday
#include<stdio.h>
main()
{
int d1,d2,d3;
int di1,di2;
int num;
int newsum;
printf("Enter a three digit number n");
scanf("%d",&num);
d1=num/100;
d2=(num%100)/10;
d3=num%10;
int sum;
sum=d1+d2+d3;
if(sum>9)
{
di1=sum/10;
di2=sum%10;
newsum=di1+di2;
}
else
{
newsum=sum;
}
printf("The Sum of digits is %d n",newsum);
switch (newsum)
{
case 1:printf("Sunday n");
break;
case 2:printf("Monday n");
break;
case 3:printf("Tuesday n");
break;
case 4:printf("Wednesday n");
break;
case 5:printf("Thursday n");
break;
case 6:printf("Friday n");
break;
case 7:printf("Saturday n");
break;
default:printf("Not a Valid Day n");
}
}
OUTPUT:
Enter a three digit number
123
The Sum of digits is 6
Friday
Recent Comments