General Solutions

General Solutions - typedef struct { char name[21]; int...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Printable Version Flag this message. From: "Kathy Edgeworth" <[email protected]> [Save Address] [Block Sender] To: "Kathy Edgeworth" <[email protected]> CC: Subject: Corrected version of today's handout part 1 Date: Mon, 2 May 2005 16:07:28 -0500 (CDT) Show Full Headers Trash As AttachmentInline Text Previous | Next 1. Given the following declaration: int ray [4] [3],i,j; Write the statements necessary to set every element in an even numbered row equal to zero and all other elements equal to 1. for (i=0;i<4;i++) for (j=0;j<3;j++) if (i%2==0) ray[i][j]=0; else ray[i][j]=1; 2. Given the following array: 8 9 12 16 49 54 87 32 Using a linear search, how many items would be examined in a search for the number 49. 5 3 Write the statements necesary to declare an array of structures which will hold the following information for up to 50 candidates: Name - up to 20 characters Delegate count by state - integer array of 50 elements Position on top 10 issues - integer array of 10 elements
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: typedef struct { char name[21]; int del_count [50]; int pos[10]; } struct_t; struct_t can_array[50]; 4. Write the instructions to read in the information for an unknown number of candidates (not to exceed 50) i=0; flag=fscanf(.%s.,can_array[0].name); while (flag!=EOf){ for (j=0;j<50;j++) flag=fscanf(.%d.,&can_array[i].del_count[j]); for (j=0;j<10;j++) flag=fscanf(.%d.,&can_array[i].pos[j]); i++; flag=fscanf(. %s.,can_array[i].name);} 6. Assume that for each of 10 issues, a 1 is stored in the position array if the candidate favors the position, and a 0 indicates the candidate is opposed. Write the instructions necessary to print a list of the names of all candidates who responded yes to 5 or more issues. for (i=0;i<count;i++) { sum=0; for (j=0;j<10;j++) if (can_array[i].pos[j]==1) sum++; if (sum>=5) printf(.%s\n.,can_array[i].name);}...
View Full Document

This note was uploaded on 12/01/2011 for the course CSC 1253 taught by Professor Staff during the Fall '08 term at LSU.

Page1 / 2

General Solutions - typedef struct { char name[21]; int...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online