#include<stdio.h>
#include<conio.h>
float add(float, float);
float sub(float, float);
float div(float, float);
float pro(float, float);
float num1, num2, res;
char oper, ext='n';
void main(){
clrscr();
while(ext!='Y' && ext!='y'){
printf("\n*****MENU*****\nOperations to perform: +, -, / & *\nEnter Operation: ");
oper=getche();
printf("\nEnter two numbers:\n");
scanf("%f%f", &num1, &num2);
switch(oper){
case '+': res=add(num1, num2); break;
case '-': res=sub(num1, num2); break;
case '/': res=div(num1, num2); break;
case '*': res=pro(num1, num2); break;
default: printf("invalid Operation!\n");
}
printf("%f %c %f = %f\n", num1, oper, num2, res);
printf("Do you want to exit (Y/N): ");
ext=getche();
}
}
float add(float n1, float n2){
return n1+n2;
}
float sub(float n1, float n2){
return n1-n2;
}
float div(float n1, float n2){
return n2>0?n1/n2:0;
}
float pro(float n1, float n2){
return n1*n2;
}
Hi guys, Recently I was working on some WP website and my client told me that he required a widget for displaying related/similar posts on the single post page. But as his website was already using many plugins, even for some pretty small tasks like this one, I decided not to use another WP plugin (plugins are not good for your WP websites, we will discuss about that on some other post.) I am not explaining the code as it is pretty simple if you are familiar with WP classes. But please let me know if you have any questions related to the PHP code posted below in the comments section or even much better, on Gist. You can add the following code directly in your child theme's functions.php file or you can create a separate file and include this at the bottom of functions.php file. <?php class similar_posts_widget extends WP_Widget { function __construct() { parent::__construct('similar_posts_...
Comments