tricky c programs with solutions
2. C program to check whether the number is EVEN or ODD using switch
3. C program to find a number of days in a month using switch case
Solution:
1.#include<stdio.h>
int main()
{
int count,n;
printf("Enter the value of N: ");
scanf("%d",&n);
count=1;
start:
printf("num: %4d, Square: %4d, Cube: %4d\n",count,(count*count),(count*count*count));
count++;
if(count<=n)
goto start;
return 0;
}
2. #include <stdio.h>
int main()
{
int number;
printf("Enter a positive integer number: ");
scanf("%d",&number);
switch(number%2)
{
case 0:
printf("%d is an EVEN number.\n",number);
break;
case 1:
printf("%d is an ODD number.\n",number);
break;
}
return 0;
}
3. #include <stdio.h>
int main()
{
int month;
int days;
printf("Enter month: ");
scanf("%d",&month);
switch(month)
{
case 4:
case 6:
case 9:
case 11:
days=30;
break;
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days=31;
break;
case 2:
days=28;
break;
default:
days=0;
break;
}
if(days)
printf("Number of days in %d month is: %d\n",month,days);
else
printf("You have entered an invalid month!!!\n");
return 0;}

Comments
Post a Comment