Identify Odd, Even & PrimeCode CrazeFeb 12, 20231 min read#include <stdio.h>void main() { int n; int choice; int sum=0,i=1; printf("\nEnter number : "); scanf("%d",&n); printf("\n1 : sum of %d numbers",n); printf("\n2 : product of %d numbers",n); printf("\n3 : check number is even"); printf("\n4 : check number is odd"); printf("\n5 : check number is prime"); printf("\n6 : factors of %d",n); printf("\nEnter your choice : "); scanf("%d",&choice); switch(choice) { case 1: { for(i=1;i<=n;i++) { sum=sum+i; } printf("\nSUM : %d",sum); break; } case 2: { int product=1,i=1; for(i=1;i<=n;i++) { product=product*i; } printf("\nPRODUCT : %d",product); break; } case 3: { if(n%2==0) { printf("\n%d is even",n); } else { printf("\n%d is not even",n); } break; } case 4: { if(n%2==1) { printf("\n%d is odd",n); } else { printf("\n%d is not odd",n); } break; } case 5: { int count=0,i; for(i=1;i<=n;i++) { if(n%i==0) { count=count+1; } } if(count==2) { printf("\n%d is prime",n); } else { printf("\n%d is not prime",n); } break; } case 6: { int count=0,i; printf("Factors of %d : ",n); for(i=1;i<=n;i++) { if(n%i==0) { printf(" %d",i); } } break; } }}
Stack Using QueueA stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...
Queue Using StackA queue can be implemented using two stacks in C. The basic idea is to use one stack for enqueue operations and another for dequeue...
Queue Using Array#include <stdio.h> #include<stdlib.h> #include<math.h> #define size 5 int queue[size]; int front = -1; int rear = -1; void enque(void);...
Comments