exe(dsna)

Share Embed Donate


Short Description

exe...

Description

DS&A EXERCISE 1. Write a program that converts a given text to "Pig Latin". Pig Latin consists of removing the first letter of each word in a sentence and placing that letter at the end of the word. This is followed by appending the word with letters "ay". #include #include #include void initialize(char english[], char piglatin[]); void readinput(char english[]); int countwords(char english[]); void convert(int words, char english[], char piglatin[]); void writeoutput(char piglatin[]); main( ) { char english[80], piglatin[80]; int words; printf("\nPig Latin Translator in C\n\n"); printf( "Type \ 'END\' when finished\n\n"); do { /* processing a new line of text */ initialize(english, piglatin); readinput(english); /* testing stopping condition */ if (toupper(english[0]) == 'E' && toupper(english[1]) == 'N' && toupper(english[2]) == 'D') break; /* count the number of words in the line */ words = countwords(english); /* Now Pig Latin Translator in C converts English to Pig Latin */ convert(words, english, piglatin); writeoutput(piglatin); } while (words >= 0); printf("\naveHay aay icenay ayday (Have a nice day)\n"); } /* initializing character arrays with blank spaces */ void initialize(char english[], char piglatin[]) { int count;

for (count = 0; count < 80; ++count) english[count] = piglatin[count] = ' '; return; } /* reading one line of text in English */ void readinput(char english[]) { int count = 0; char c; while (( c = getchar()) != '\n') { english[count] = c; ++count; } return; } /* scanning the given message or line of text and determining the number of words in it */ int countwords(char english[]) { int count, words = 1; for (count = 0; count < 79; ++count) if (english[count] == ' ' && english[count + 1] != ' ') ++words; return (words); } /* now Pig Latin translator in C coverts each word into Pig Latin */ void convert(int words, char english[], char piglatin[]) { int n, count; int m1 = 0; /* m1 indicates the position of beginning of each word */ int m2; /* m2 indicates the end of the word */ /* convert each word */ for (n = 1; n 0) { printf("\n c=%lf temp=%lf i=%d",c,temp,i); temp=(int)c%10; x[i]=(int)temp; c=(int)c/10; i--; getch(); } } if( (x[0]==x[4])&& (x[1]==x[5]) &&(x[2]==x[6]) && (x[3]==x[7]) ) { printf("\t %lf is required number.",a); } else { printf("\t %lf is not required number.",a); } getch(); }

3. Given an integer n > 1 and an integer p > 1 you are to write a program that determines the positive nth root of p. In this problem, given such integers n and p, p will always be of the form k^n for an integer k ( this integer is what your program much find). #include int main() { int n,p,k,var,i; scanf("%d%d",&n,&p); for(k=1;k
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF