Search This Blog

Monday, 18 May 2020

programming C( switch structure)

   even number and odd number(if and switch content)

if content


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int no,ans;
    printf("enter a number");
    scanf("%d",&no);

    ans=no%2;

    if(ans==0)
    printf("%d is an even number",no);

    else
    printf("%d is an odd number",no);

    return 0;
}

write the above programe using switch

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int no,ans;
   printf("enter a number");
   scanf("%d",&no);

   ans=no%2;

   switch(ans)
   {
       case 0:printf("%d is an even",no);break;
       case 1:printf("%d is an odd",no);break;
   }

}

 

    

No comments:

Post a Comment

please wait...