Вы находитесь на странице: 1из 6

1 // include the library for various operations #include <string.h> #include <stdio.h> #include <ctype.

h> // define static arrays of character data types static char givenLetters[6] = { 'A', 'B', 'E', 'I', 'O', 'S' }; static char numberValue[6] = { '4', '8', '3', '1', '0', '5' }; // main function of the program int main() { // array to hold the user values char userString[100]; // pointer variables char* indexValue; char* temp; // variable of int data type int loop; printf("Please enter the string: "); gets(userString); // loop to convert the lower case string to upper case for (temp = userString; *temp; temp++) { // convert the characters to upper case *temp = toupper(*temp); } // loop to replace characters with numbers for (temp = userString; *temp; temp++) // condition for replacement if (indexValue = strchr(givenLetters, *temp)) // replace values *temp = numberValue[indexValue givenLetters]; // loop to append ! for (loop = 0; loop < 5;loop++) // append ! *temp++ = '!'; temp = '\0'; // display the string printf("C1GG message: %s\n", userString); // successful termination indicated return 0; } -

Sample output: Please enter the string: Hey dude, C is rilly cool C1GG message: H3Y DUD3, C 15 R1LLY C00L!!!!!"

2 // include the library for various input output operations #include <stdio.h> // define polynomial function to find the value of equation int polyFunction() { // define variable of int data type int number1, number2; //display message to prompt user printf("Please enter the value of X:"); // input value scanf("%d", &number1); // calculate the value of function number2 = 3*number1^5 + 2*number1^4 - 5*number1^3 number1^2 - 7*number1 - 6; // display the value of equation printf("\nThe value of equation is : %d", number2); return 0; } int main() { // call the function polyFunction(); // successful termination indicated return 0; }

Sample Output: Please enter the value of X:2 The value of equation is : 26

3 // include the library for various input/output operations #include <stdio.h> #include <conio.h> #include <string.h> // main function of the program int main() { // define array of char data type char strArray[30], revStrArray[30]={'\0'}; // define variables of int data type int loop,lengthOfString = 0, flagValue = 0; // flush the memory fflush(stdin); // display the message printf("Enter a message\n"); gets(strArray); // loop to calculate the length of the string for (loop=0; strArray[loop] != '\0'; loop++) { lengthOfString++; } // loop to assign value to other array for (loop=lengthOfString-1; loop >= 0 ; loop--) { revStrArray[lengthOfString-loop-1] strArray[loop]; } // loop to check palindrome string for (loop=0; loop < lengthOfString ; loop++) { // condition to check palindrome string if (revStrArray[loop] == strArray[loop]) // set the value flagValue = 1; else // set the value flagValue = 0; } // condition to display message if (flagValue == 1) // display message printf ("The message strArray); else // display message printf("The message strArray); entered is not palindrome\n", entered is palindrome\n",

// successful termination indicated return 0; }

Sample Output: Enter a message Madam, I am Adam. The message entered is not palindrome

4 // include library for various input/output operations #include <stdio.h> #include <string.h> // define the structure struct date { // member variables of the structure int valueOfDate; int valueOfMonth; int ValueOfYear; }; // main function of the program int main(void) { // define objects of the structure struct date D1,D2; // define variables of int data type int dayvalue,monthValue,yearValue,flag=0; // prompt the user to input values for the first date printf("Please enter first day"); scanf("%d",&dayvalue); printf("Please enter first month"); scanf("%d",&monthValue); printf("Please enter first year"); scanf("%d",&yearValue); // set the values to the object of the structure D1.valueOfDate=dayvalue; D1.valueOfMonth=monthValue; D1.ValueOfYear=yearValue; // prompt the user to input printf("Please enter second scanf("%d",&dayvalue); printf("Please enter second scanf("%d",&monthValue); printf("Please enter second scanf("%d",&yearValue); values for the second date day"); month"); year");

// set the values to the object of the structure D2.valueOfDate=dayvalue; D2.valueOfMonth=monthValue; D2.ValueOfYear=yearValue; // condition to check the value of the year if (D1.ValueOfYear < D2.ValueOfYear) // set the value of the flag flag= -1; else // condition to check value of the year if (D1.ValueOfYear > D2.ValueOfYear) // set the value of the flag flag= 1; // condition to check equal values of the year if (D1.ValueOfYear = D2.ValueOfYear) // set the value of the flag flag= -1; // condition to check value of the month if (D1.valueOfMonth<D2.valueOfMonth) // set the value of the flag flag= -1; else // condition to check value of the month if (D1.valueOfMonth>D2.valueOfMonth) // set the value of the flag flag= 1; else // condition to check value of the day if (D1.valueOfDate<D2.valueOfDate) // set the value of the flag flag= -1; else // condition to check value of the day if(D1.valueOfDate>D2.valueOfDate) // set the value of the flag flag= 1;

// condition to display message if(flag == 1) // display message printf("First date is greater"); else // display message printf("Second date is greater"); // successful termination indicated return 0; }

Sample output: Please Please Please Please Please Please Second enter first day3 enter first month8 enter first year2010 enter second day5 enter second month17 enter second year2011 date is greater

5 // include the library for various operations #include<stdio.h> #include<math.h> #include<conio.h> // main function of the program int main(void) { // declare variables of double data type float ccVal1,ccVal2,polarR,thetaAngle; // display the message printf("Please input coordinates\n"); the values of cartesian

// prompt the user to input the values scanf("%f%f",&ccVal1,&ccVal2); // calculate the value of radian polarR=sqrt((ccVal1*ccVal1) + (ccVal2*ccVal2)); // calculate the theta angle thetaAngle=atan(ccVal2/ccVal1); // convert the angle in degree value thetaAngle=(thetaAngle*180)/3.14; // display the message printf("\nThe values of the polar coordinates are %f and %f" ,polarR,thetaAngle); // successful termination indicated return 0; }

Sample output: Please input the values of cartesian coordinates 2 3 The values 56.338493 of the polar coordinates are 3.605551 and

Вам также может понравиться