Rainbow
This program will draw a rainbow.
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<graphics.h>
float translate(float value, float leftMin,float leftMax,float rightMin,float rightMax){
// Figure out how 'wide' each range is
float leftSpan = leftMax - leftMin;
float rightSpan = rightMax - rightMin;
//# Convert the left range into a 0-1 range (float)
float valueScaled =(value - leftMin) /(leftSpan);
//# Convert the 0-1 range into a value in the right range.
return rightMin + (valueScaled * rightSpan);
}
Driver Code
#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<graphics.h>
float translate(float value, float leftMin,float leftMax,float rightMin,float rightMax){
// Figure out how 'wide' each range is
float leftSpan = leftMax - leftMin;
float rightSpan = rightMax - rightMin;
//# Convert the left range into a 0-1 range (float)
float valueScaled =(value - leftMin) /(leftSpan);
//# Convert the 0-1 range into a value in the right range.
return rightMin + (valueScaled * rightSpan);
}
Driver Code