lab3RGB.c file:
#include <stdio.h> #define AlphaValue 100 int main() { int r, g,b; unsigned int rgb_pack; int r_unpack, g_unpack,b_unpack; int alpha = AlphaValue; printf("enter R value (0~255): "); scanf("%d",&r); printf("enter G value (0~255): "); scanf("%d",&g); printf("enter B value (0~255): "); scanf("%d",&b); while(! (r<0 || g<0 || b <0) ) { printf("A: %d\t", alpha); printBinary(alpha); printf("\n"); printf("R: %d\t", r); printBinary(r); printf("\n"); printf("G: %d\t", g); printBinary(g); printf("\n"); printf("B: %d\t", b); printBinary(b); printf("\n"); /* do the packing */ //printf("\nPacked: value %d\t", rgb_pack); printBinary(rgb_pack);printf("\n"); printf("\nPacked:\t"); printBinary(rgb_pack);printf(" (%d)\n", rgb_pack); printf("\nUnpacking ......\n"); /* do unpacking */ printf("R: "); printBinary(r_unpack); printf(" (%d, %#o, %#X)\n", r_unpack, r_unpack, r_unpack); printf("G: "); printBinary(g_unpack); printf(" (%d, %#o, %#X)\n", g_unpack, g_unpack, g_unpack); printf("B: "); printBinary(b_unpack); printf(" (%d, %#o, %#X)\n", b_unpack, b_unpack, b_unpack); printf("------------------------------------\n"); /* read again */ printf("\nenter R value: "); scanf("%d",&r); printf("enter G value: "); scanf("%d",&g); printf("enter B value: "); scanf("%d",&b); } }
-------------------------Screenshot-----------------------
-------------------------Code-----------------------
#include <stdio.h>
#define AlphaValue 100
void printBinary(int a){
char binary[33];
for(int i=31;i>=0;i--){
binary[i] = '0'+(a%2);
a/=2;
}
binary[32] = '\0';
for(int i=0;i<32;i++){
printf("%c",binary[i]);
if(i>0 && ((i+1)%8==0) && i!= 31) printf("
");
}
}
int main() {
int r, g,b;
unsigned int rgb_pack;
int r_unpack, g_unpack,b_unpack;
int alpha = AlphaValue;
printf("enter R value (0~255): ");
scanf("%d",&r);
printf("enter G value (0~255): ");
scanf("%d",&g);
printf("enter B value (0~255): ");
scanf("%d",&b);
while(! (r<0 || g<0 || b <0) )
{
printf("A: %d\t", alpha); printBinary(alpha); printf("\n");
printf("R: %d\t", r); printBinary(r); printf("\n");
printf("G: %d\t", g); printBinary(g); printf("\n");
printf("B: %d\t", b); printBinary(b); printf("\n");
/* do the packing */
rgb_pack = 0;
rgb_pack = rgb_pack | (alpha<<24);
rgb_pack = rgb_pack | (r<<16);
rgb_pack = rgb_pack | (g<<8);
rgb_pack = rgb_pack | (b<<0);
//printf("\nPacked: value %d\t", rgb_pack);
printBinary(rgb_pack);printf("\n");
printf("\nPacked:\t"); printBinary(rgb_pack);printf(" (%d)\n",
rgb_pack);
printf("\nUnpacking ......\n");
/* do unpacking */
int rmask = ((1<<8)-1)<<16;
r_unpack = (rgb_pack & rmask)>>16;
int gmask = ((1<<8)-1)<<8;
g_unpack = (rgb_pack & gmask)>>8;
int bmask = ((1<<8)-1)<<0;
b_unpack = (rgb_pack & bmask)>>0;
printf("R: "); printBinary(r_unpack); printf(" (%d, %#o, %#X)\n",
r_unpack, r_unpack, r_unpack);
printf("G: "); printBinary(g_unpack); printf(" (%d, %#o, %#X)\n",
g_unpack, g_unpack, g_unpack);
printf("B: "); printBinary(b_unpack); printf(" (%d, %#o, %#X)\n",
b_unpack, b_unpack, b_unpack);
printf("------------------------------------\n");
/* read again */
printf("\nenter R value: ");
scanf("%d",&r);
printf("enter G value: ");
scanf("%d",&g);
printf("enter B value: ");
scanf("%d",&b);
}
}
lab3RGB.c file: #include <stdio.h> #define AlphaValue 100 int main() { int r, g,b; unsigned int rgb_pack...
Solve using C programming
3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...
(Packing Characters into an Integer) The left-shift operator can be used to pack four character values into a four-byte unsigned int variable. Write a program that inputs four characters from the keyboard and passes them to function packCharacters. To pack four characters into an unsigned int variable, assign the first character to the unsigned intvariable, shift the unsigned int variable left by 8 bit positions and combine the unsigned variable with the second character using the bitwise inclusive OR operator....
#include<stdio.h> int main() { int i; printf("Type an integer value: "); scanf("%d",&i); evaluate(i); return(0); } void evaluate(int x) { if(x > 10) printf("Value entered by you is greater than 10"); else if(x < 10) printf("Value entered by you is less than 10"); else printf("Value entered by you is equal 10"); } _______________________________________ report for this in hr ?
How do i finish this code: #include <stdio.h> int main() { long long decimal, tempDecimal, binary; int reminder, weight = 1; binary = 0.0; //Input decimal number from user printf("Enter any decimal number: "); scanf("%lld", &decimal); // Since we do not want change the value of decimal in the code // let us use tempDecimal to store the value of decimal tempDecimal = decimal; printf("\n\n"); // Let us use while loop first to implement printf("while loop part:\n"); /**************START FROM HERE...
#include <stdio.h> #include<string.h> int main() { char strText[100] ="Start"; char i; int nTextASCIISum = strText[0] + strText[1] + strText[2]; int nTextLen = strlen(strText); int count = 0; printf("Welcome to token generator!\n"); printf("Enter a word to use in the token generator.\n You may enter as many words as you like. \n Press q and key when finished.\n"); scanf("%c", &strText[i]); //compute when to stop loop //check nTextLen == 1 and strText[0] == 'q' for(i=0;i< nTextLen;i++) if ((strlen(strText) != 1) || (strText[0] !=...
10.11 (Left Shifting Integers ) Left shifting an unsigned int by
1 bit is equivalent to multiplying the value by 2. Write function
power2 that takes two integer arguments number and pow and
calculates number * 2pow. You should declare pow as an unsigned
integer , but remember that the result may be a negative value .
Use the shift operator to calculate the result. Print the values as
integers and as bits . Assume that an integer is of...
sort.c
#include <stdlib.h>
#include <stdio.h>
#include "libsort.h"
int main()
{
int* array;
int size, c;
float median;
printf("Enter the array size:\n");
scanf("%d", &size);
array = (int*) malloc(size *
sizeof(int));
printf("Enter %d integers:\n", size);
for (c = 0; c < size; c++)
scanf("%d",
&array[c]);
sort(array, size);
printf("Array sorted in ascending
order:\n");
for (c = 0; c < size; c++)
printf("%d ",
array[c]);
printf("\n");
median = find_median(array,...
5.43 (10 pts) What does the following program do? #include <stdio.h> 3 unsigned int mystery Cuns igned int a, unsigned int b): // function prototype 5 int main(void) printf("%s". "Enter two positive integers: unsigned int x: I/ first integer unsigned int y: // second integer scanf("Su%u". &x, &y); "); 12 13 14 15 II Parameter b must be a positive integer 16 to prevent infinite recursion 7 unsigned int mystery Cuns igned int a, unsigned int b) 18 printf("The result...
In C, thanks.
#include <stdio.h> void set-flag (unsigned int* flag-holder , int flag-position); void unset-flag (unsigned int * flag-holder, int flag-position); int check-flag (unsigned int flag-holder , int flag-position); void display -32_flags (unsigned int flag-holder); int main(int argc, char* argv (1) unsigned int flag -holder = 0; set-flag (& flag-holder, 3); set-flag (& flag-holder, 16); set-flag (& flag-holder, 31); display-32-flags (flag-holder); unset-flag(& flag-holder , 31); unset-flag (& flag-holder, 3); set-flag (& flag-holder , 9); display-32-flags (flag-holder ); return 0; Write...
Code that needs to be modified: #include #include #include int main() { int i,N,x; unsigned int seed; double R; printf("\nEnter number of iterations and seed"); printf("\n"); scanf("%i %u", &N,&seed); srand(seed); for(i=0;i { R=(double)rand()/RAND_MAX; if (R<0.5) x=x+1; else x=x-1; } printf("Final location is "); printf("%d",x); printf("\n"); } Question: Write a code that generates N pairs of random numbers. Call the first member of each pair x and the second member y. Count how many of the N pairs obey x^2+y^2<1. Call...