C PROGAMMING QUESTIONS --> FUNCTION

Leave a Comment

**********************QUESTION ********************************


 Consider all integers in the given interval [20, 70]. Write a function to return the

number of even integers that are divisible by a random number k, where 1 £ k £ 20. Here an

integer x is divisible by k is defined as: x o 0 (mod k).


***************************SOLUTION*****************************


#include<stdio.h> #include<stdlib.h> #include<time.h> int even(int); int main(){ int n=0; printf("\nnumber of even integers=%d\n",even(n)); return 0; } int even(x){ int k,i,n=0; srand(time(0)); k=rand()%20+1; printf("random number=%d\n",k); for(int x=10;x<=70;x++){ if(x%2==0&&x%k==0){ printf("%d\t",x); n++; } } return n; }



        THANK YOU !!!!

THIS CODE IS WRITTEN BY HACKINGALLTOU.BLOGSPOT.COM

                LIKE US ON FB  

0 comments: