Question

#include #include <stdio.h> <stdlib.h> void make_pixel (int r, int g, int b); void make-ppm-header (int width, int height); v

ImageMagick: poland.ppm

I want to create the flags for Poland, the Netherlands, and Italy using ppm files and file redirection. I can't seem to get my pixels lined up correctly to make my flags. Here's my output for when I tried to make my flag for Poland. Any way to fix this?

I am working in C

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ans............................................

code in c to make flags:

.............................................................................................................................................................................................................................................................................................................................

#include<stdio.h>

int main(){

   int country_choice;

   int width;

   int height;

   int i, j, k, t;

   fprintf(stderr, "Enter the country_code of the chosen flag.(1 for Poland, 2 for Netherlands, 3 for Italy)");

fscanf(stdin,"%d",&country_choice);

fprintf(stderr,"Enter the width of the flag ");

   fscanf(stdin, "%d", &width);

height=(width*2)/3;

  

switch (country_choice) {

case 1:
   
   printf("Poland Flag\n");
   
   for(i=0;i<width;i++){
   
   for(j=0; j<width/3; j++){
   
   printf("%c%c%c", 255,255,255);
   
   for(k=0; k<width/3; k++){
   
   printf("%c%c%c", 220,20,60);
   
   }
   
   }
   
   }
   break;

case 2:

   printf("Italian Flag\n");
   
   for(i=0; i<height; i++){
   
   for(j=0; j<width/3; j++){
   
   printf("%c%c%c", 0,146,70);
   
   for(k=0; k<width/3; k++){
   
   printf("%c%c%c", 225,255,255);
   
   for(t=0; t<width/3; t++){
   
   printf("%c%c%c", 206,43,55);
   
   }
   
   }
   
   }
   
   }
   
   break;
   

case 3:

   printf("Netherlands Flag\n");
   
   for(i=0; i<height; i++){
   
   for(j=0; j<width/3; j++){
   
   printf("%c%c%c", 174,28,40);
   
   for(k=0; k<width/3; k++){
   
   printf("%c%c%c", 225,255,255);
   
   for(t=0; t<width/3; t++){
   
   printf("%c%c%c", 33,70,139);
   
   }
   
   }
   
   }
   
   }
   
   break;
default:
   printf("Wrong Option");
   break;

}

   return(0);

}

..............................................................................................................................................................................................................................................................................................................................

output:

Add a comment
Know the answer?
Add Answer to:
I want to create the flags for Poland, the Netherlands, and Italy using ppm files and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program called flags.c that is capable of creating an image of the flags of...

    Write a program called flags.c that is capable of creating an image of the flags of Poland, Netherland, and Italy. country_code should be 1, 2, and 3 for Poland, the Netherlands, and Italy, respectively. Here's my code so far #include<stdio.h> void make_pixel(int r,int g, int b); void make_ppm_header(int width,int height); void make_ppm_image(int country_code, int width); int main(){    int width=0;    int country_code=0;    fprintf(stderr, "Enter the country_code of the chosen flag.(1 for Poland, 2 for Netherlands, 3 for Italy)");    fscanf(stdin,...

  • Your program should be capable of creating a ppm image of the flag of Benin • The new flag gener...

    Your program should be capable of creating a ppm image of the flag of Benin • The new flag generated should use the proper width-to-height ratio as defined on Wikipedia for the flag. o For the colors, use pure red, and yellow, and a value of 170 for green. ▪ Pure color values are talked about in Lab 6. o The left green field should be 6/15ths of the width of the flag. Variables country_code should also include a new...

  • In C using the following 2 files to create a 3rd file that uses multiple threads...

    In C using the following 2 files to create a 3rd file that uses multiple threads to improve performance. Split the array into pieces and each piece is handled by a different thread. Use 8 threads. run and compile in linux. #include <stdio.h> #include <sys/time.h> #define BUFFER_SIZE 4000000 int countPrime=0; int numbers[BUFFER_SIZE]; int isPrime(int n) { int i; for(i=2;i<n;i++) if (n%i==0) return 0; return 1; } int main() { int i; // fill the buffer for(i=0;i<BUFFER_SIZE;i++) numbers[i] = (i+100)%100000; //...

  • so in this code, it computes the sum 1+2+....+n but i want it to compute 2*(1+2+....+n)...

    so in this code, it computes the sum 1+2+....+n but i want it to compute 2*(1+2+....+n) using semaphores implement solution to the critical section problem #include #include int sum; /* this data is shared by the thread(s) */ void *runner(void *param); /* threads call this function */ int main(int argc, char *argv[]) { pthread_t tid; /* the thread identifier */ pthread_attr_t attr; /* set of thread attributes */ if (argc != 2) { fprintf(stderr,"usage: a.out \n"); return -1; } if...

  • Create another program that will prompt a user for input file. The user will choose from...

    Create another program that will prompt a user for input file. The user will choose from 4 choices: 1. Display all positive balance accounts. 2. Display all negative balance accounts. 3. Display all zero balance accounts. 4. End program. C PROGRAMMING my code so far #include<stdlib.h> #include<stdio.h> int main(void) { int request; int account; FILE *rptr; char name[20]; double balance; FILE *wptr;    int accountNumber;    if((wptr = fopen("clients.dat","w")) == NULL) { puts("File could not be opened"); } else {...

  • C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want...

    C Programming - RSA Encryption I've tried to write a program that can encrypt and decrypt strings using RSA and want to be able to integrate it into a header file which contains codes for compression, linked list etc.. However, the use of global variables and fixed size of encryption is making it hard to do so Can someone please help me modify the following the code? I want to be able to just pass it in a string to...

  • Pleas help I need to create and array to add to my code something like this...

    Pleas help I need to create and array to add to my code something like this for (i = 0; i < NUM_THREADS; ++i) { thr_data[i].tid = i; if ((rc = pthread_create(&thr[i], NULL, thr_func, &thr_data[i]))) { fprintf(stderr, "error: pthread_create, rc: %d\n", rc); return EXIT_FAILURE; ::::::::: CODE ::::::::::::: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <pthread.h>    int sharedVar = 0; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* thread handler */ void *threadHandler(void *vargp) {    int i = 0;    pthread_mutex_lock(&mutex);   ...

  • I need to make it so this program outputs to an output.txt, the program works fine,...

    I need to make it so this program outputs to an output.txt, the program works fine, just need it to fprintf to output.txt #include <stdio.h> #include <string.h> #include <malloc.h> #define MAX 30 struct treeNode { char names[MAX];    struct treeNode *right; struct treeNode *left; }*node; void searchName(char names[], struct treeNode ** parent, struct treeNode ** location) { struct treeNode * ptr, * tempPtr; if(node == NULL)    { *location = NULL; *parent = NULL; return; } if(strcmp(names, node->names) == 0)...

  • Please help modify my C program to be able to answer these questions, it seems the...

    Please help modify my C program to be able to answer these questions, it seems the spacing and some functions arn't working as planeed. Please do NOT copy and paste other work as the answer, I need my source code to be modified. Source code: #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { char title[50]; char col1[50]; char col2[50]; int point[50]; char names[50][50]; printf("Enter a title for the data:\n"); fgets (title, 50, stdin); printf("You entered: %s\n", title);...

  • Hello, how can i compile this C code using option -std=c99 or -std=gnu99 #include <stdio.h> #include...

    Hello, how can i compile this C code using option -std=c99 or -std=gnu99 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <unistd.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> #include <fcntl.h> static char* args[512]; pid_t pid; int command_pipe[2]; static void waiting(int n); static int command(int input, int first, int last) { int fd[2]; int flag=0; pipe( fd );   pid = fork(); if (pid == 0) { for(int i=0;args[i]!=0;i++) { if(args[i][0]=='>') { fd[1]=open(args[i+1], O_CREAT|O_TRUNC|O_WRONLY, 0644); flag=1; } if(args[i]=='>>' ) { fd[1]=open(args[i+1],...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT