Question

You have to clearly define what each if statement is doing in both programs. #include <stdio.h>...

You have to clearly define what each if statement is doing in both programs.

#include <stdio.h>

static unsigned char count = 31;

void callMe ( char ch )
{


if ( ch == 'U' || ch == 'u') {

if ( count > 15 )
count -= 16;
printf ( "count = %d \n", count ) ;
return;
}

if ( ch == 'A' || ch == 'a') {
if ( count % 2 == 1)
count -= 1;
printf ( "count = %d \n", count ) ;
return;
}

if ( ch == 'o' || ch == 'O') {
if ( (count / 8 == 3) || (count / 8 == 1) )
count -= 8;
printf ( "count = %d \n", count ) ;
return;
}

if ( ch == 'i' || ch == 'I') {
if ( (count / 4 == 7) || (count / 4 == 5)
|| (count / 4 == 3) || (count / 4 == 1 ) )
count -= 4;
printf ( "count = %d \n", count ) ;
return;
}

if ( ch == 'e' || ch == 'E') {
if ( (count / 2 == 15 ) || (count / 2 == 13 )
|| (count / 2 == 11 ) || (count/2 == 9 )
|| (count/2 == 7 ) || (count/2 == 5 ) || ( count/2 == 3 || ( count/2 == 1 ))
)
count -= 2;
printf ( "count = %d \n", count ) ;
return;
}

}
int main(void) {
printf ( "Please enter a string of character\n");
char ch = getchar ( ) ;
while ( ch != '\n') { callMe (ch); ch = getchar() ;}

if (count ) {
printf ( "Some letters are missing \n");
printf ( " %d \n", count );
}

return 0;
}


2.
int main ( )
{
// COMMENT ALL THE LINES EXCEPT ONE
char data [ 16 ] = "aa";
//char data [ 16 ] = "Hello";
//char data [ 16 ] = "CSU";
//char data [ 16 ] = "happy";

unsigned char len = strlen ( data); // returns the length of data

int i = 0, temp = 0 ;

for ( i = 0 ; i < len ; i++)
{
char ch = toupper ( data [ i] ); // converts lower case to upper case

if ( temp & ( 1 << ( ch - 65 ) ) ) //it was i, it should be 1
{
printf ( " THis is not good a string \n") ;
// you could call printBits function here to see the value of temp
return 0; // added return
}
else {
temp = temp | ( 1 << ( ch - 65 ) ) ; // it was <, it should be <<
// you could call printBits function here to see the value of temp
}
}

printf ( "This is a good string\n");

}

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

Program 1 commented with each if statement :

#include <stdio.h>

static unsigned char count = 31;

void callMe ( char ch )
{

//check entered char is "U" or "u"
if ( ch == 'U' || ch == 'u') {
//check count value is greater than 15
if ( count > 15 )
//subtract count with 16
count -= 16;
printf ( "count = %d \n", count ) ;1
return;
}
//check entered char is "A" or "a"
if ( ch == 'A' || ch == 'a') {
//check remainder of dividing count by 2 is equal to 1
if ( count % 2 == 1)
//subtract count with 1
count -= 1;
printf ( "count = %d \n", count ) ;
return;
}
//check entered char is "o" or "O"
if ( ch == 'o' || ch == 'O') {
//check quotient of (count/8) equal to 3 or 1
if ( (count / 8 == 3) || (count / 8 == 1) )
//subtract count with 8
count -= 8;
printf ( "count = %d \n", count ) ;
return;
}
//check entered char is "i" or "I"
if ( ch == 'i' || ch == 'I') {
//check quotient of (count/4) equal to 7 or 5 or 3 or 1
if ( (count / 4 == 7) || (count / 4 == 5)
|| (count / 4 == 3) || (count / 4 == 1 ) )
//subtract count with 4
count -= 4;
printf ( "count = %d \n", count ) ;
return;
}
//check entered char is "e" or "E"
if ( ch == 'e' || ch == 'E') {
//check quotient of (count/2) equal to 15 or 13 or 11 or 9 or 7 or 5 or 3 or 1
if ( (count / 2 == 15 ) || (count / 2 == 13 )
|| (count / 2 == 11 ) || (count/2 == 9 )
|| (count/2 == 7 ) || (count/2 == 5 ) || ( count/2 == 3 || ( count/2 == 1 ))
)
//subtract count with 2
count -= 2;
printf ( "count = %d \n", count ) ;
return;
}

}
int main(void) {
printf ( "Please enter a string of character\n");
char ch = getchar ( ) ;
while ( ch != '\n') { callMe (ch); ch = getchar() ;}
//check count is greater than 0 or not
if (count) {
printf ( "Some letters are missing \n");
printf ( " %d \n", count );
}

return 0;
}

Program 2 commented with each if statement :

int main ( )
{
// COMMENT ALL THE LINES EXCEPT ONE
char data [ 16 ] = "aa";
//char data [ 16 ] = "Hello";
//char data [ 16 ] = "CSU";
//char data [ 16 ] = "happy";

unsigned char len = strlen (data); // returns the length of data

int i = 0, temp = 0 ;

for ( i = 0 ; i < len ; i++)
{
char ch = toupper ( data [i] ); // converts lower case to upper case

//check bitwise "and" operation performed with temp & value obtained after left shift of "1" by (ch-65) evaluates to TRUE
if ( temp & ( 1 << ( ch - 65 ) ) ) //it was i, it should be 1
{
printf ( " THis is not good a string \n") ;
// you could call printBits function here to see the value of temp
return 0; // added return
}
else {
//perform bitwise "or" operation with temp & value obtained after left shift of "1" by (ch-65) & store back to temp
temp = temp | ( 1 << ( ch - 65 ) ) ; // it was <, it should be <<
// you could call printBits function here to see the value of temp
}
}

printf ( "This is a good string\n");

}

Add a comment
Know the answer?
Add Answer to:
You have to clearly define what each if statement is doing in both programs. #include <stdio.h>...
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
  • How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include...

    How can I integrate these programs into this menu template: #define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include void program_one (); void program_two (); void program_three (); void program_four(); void program_five(); int main() { int menu_option = 0; while (menu_option != 9) { printf(" = 1\n"); //Change this to your first program name. Nothing else. printf(" = 2\n"); //Change this to your second program name. Nothing else. printf(" = 3\n"); //Change this to your third program name. Nothing else. printf(" =...

  • #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str);...

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include<ctype.h> #define MAX_LEN 255 int numWords(char *str); int numDigit(char *str); int numUppltr(char *str); int numLwrltr(char *str); int punChar(char *str); char*readString(char *str); int main() { char givString[MAX_LEN]; puts("Enter your string(Max 255 characters):"); //readString(givString); gets(givString); printf("\nnumber of words :%d",numWords(givString)); printf("\nnumber of uppercase letters %d",numUppltr(givString)); printf("\nnumber of lowercase letters %d",numLwrltr(givString)); printf("\nnumber of punctuations %d\n",punChar(givString)); printf("\nnumber of digits:%d\n",numDigit(givString)); system("pause"); return 0; } char *readString(char *str) { int ch, i=0; while((ch=getchar())!=EOF && ch!='\n') { if(i) { str[i]=ch; i++; }...

  • C Programming // Compile with: clang radio.c -o radio // Run with: ./radio #include <stdio.h> #include...

    C Programming // Compile with: clang radio.c -o radio // Run with: ./radio #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // @Name    loadMusicFile // @Brief   Load the music database //          'size' is the size of the database. char** loadMusicFile(const char* fileName, int size){ FILE *myFile = fopen(fileName,"r"); // Allocate memory for each character-string pointer char** database = malloc(sizeof(char*)*size); unsigned int song=0; for(song =0; song < size; song++){       // Allocate memory for each individual character string       database[song] =...

  • PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int...

    PLease explain output of these two programs: 1. #include <stdio.h> typedef struct { char *name; int x, y; int h, w; } box; typedef struct { unsigned int baud : 5; unsigned int div2 : 1; unsigned int use_external_clock : 1; } flags; int main(int argc, char** argv){ printf("The size of box is %d bytes\n", sizeof(box)); printf("The size of flags is %d bytes\n", sizeof(flags)); return 0; } 2. #include <stdio.h> #include <string.h> /* define simple structure */ struct { unsigned...

  • C Language! Please, comment what each line of code does in the code below and answer...

    C Language! Please, comment what each line of code does in the code below and answer this question: (sentence is fine) 1. Aside from pressing ctrl-(d/z) at the beginning of a line causing the getnchar() function to return NULL, is there any way to enter less than 9 characters? Code: void exer1(void) {    char input[LEN];    char *check; getchar(); // Clearing character buffer. printf("Please enter 9 characters: "); // Prompting the user to enter // a specific input.   ...

  • Finish function to complete code. #include <stdio.h> #include <stdlib.h> #include<string.h> #define Max_Size 20 void push(char S[],...

    Finish function to complete code. #include <stdio.h> #include <stdlib.h> #include<string.h> #define Max_Size 20 void push(char S[], int *p_top, char value); char pop(char S[], int *p_top); void printCurrentStack(char S[], int *p_top); int validation(char infix[], char S[], int *p_top); char *infix2postfix(char infix[], char postfix[], char S[], int *p_top); int precedence(char symbol); int main() { // int choice; int top1=0; //top for S1 stack int top2=0; //top for S2 stack int *p_top1=&top1; int *p_top2=&top2; char infix[]="(2+3)*(4-3)"; //Stores infix string int n=strlen(infix); //length of...

  • Question 6 Predict the output of the following question: 8 pts #include <stdio.h> #include<string.h> char al(5)={...

    Question 6 Predict the output of the following question: 8 pts #include <stdio.h> #include<string.h> char al(5)={ "gate", "kate","rate","date" ); void rec(char a[][5], int n){ if(n<= 1) return; char temp[5]; strcpy(temp'a);//copies the string stored in a into temp strcpy(*a,a[n-1]); strcpy(a[n-1),temp); rec(a+1,n-2); } void main() { rec(a 4); int i = 0; for(;i<4;i++) a[i][4]+= 10; printf("%s", a); }

  • #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here....

    #include <stdio.h> #include <string.h> #include <ctype.h> #include <stdlib.h> int main(void) { /* Type your code here. */ int GetNumOfNonWSCharacters(const char usrStr[]) { int length; int i; int count = 0; char c; length=strlen(usrStr); for (i = 0; i < length; i++) { c=usrStr[i]; if ( c!=' ' ) { count++; } }    return count; } int GetNumOfWords(const char usrStr[]) { int counted = 0; // result // state: const char* it = usrStr; int inword = 0; do switch(*it)...

  • Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */...

    Please explain how these code run for each line #include<stdio.h> #include<string.h> /** * Part A */ struct myWord{    char Word[21];    int Length; }; int tokenizeLine(char line[], struct myWord wordList[]); void printList(struct myWord wordList[], int size); void sortList(struct myWord wordList[], int size); /** * main function */ int main() {    struct myWord wordList[20];    char line[100];    printf("Enter an English Sentence:\n");    gets(line);    int size = tokenizeLine(line, wordList);    printf("\n");    printf("Unsorted word list.\n");    printList(wordList, size);...

  • What are the description of approach or technique used in this? #include <stdio.h> long charCount=0; long...

    What are the description of approach or technique used in this? #include <stdio.h> long charCount=0; long digitCount=0; long lineCount=0; long wordCount=0; long digitFreq[10]; int c=0; int outOfWord=0; int state=0; int inWord=1; void printStats(); void totalWords(); void totalLines(); void digitFrequency(); int main(int argc,char **argv) { int i; for(i=0;i<10;i++) { digitFreq[i]=0; } state=outOfWord; c=getchar(); while((c !=EOF)) { charCount++; digitFrequency(c); totalLines(c); totalWords(c); c=getchar(); } printStats(); return 1; } void totalLines(int c) { if(c == '\n') { lineCount++; } } void digitFrequency(int c) {...

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