Program to write function performing operations on integer


C File =>


/* Write a function which accepts a number and three flags as parameters if number is even set first flag to 1. If number is prime set second flag to 1 and if number is divisible by 3 or 7 set the third flag to 1(pass addresses of flags to the function.) */


#include<stdio.h>
int main()
{
     int n,i,flag1=0,flag2=1,flag3=0;
     void set_flag(int n,int *f1,int *f2,int *f3)
    {
         if(n%2==0)
           *f1=1;
         for(i=2;i<n-1;i++)
        {
              if(n%i==0)
             {
                  *f2=0;
                  break;
              }
         }
     
        if(n%3==0 || n%7==0)
          *f3=1;
       }
       printf("\n Enter Number : ");
       scanf("%d",&n);
       set_flag(n,&flag1,&flag2,&flag3);
       if(flag1==1)
           printf("\n Number is even..");
       if(flag2==1)
           printf("\n Number is Prime..");
       if(flag3==1)
           printf("\n Number is divisible by 3 or 7");
    return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.