{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Assignment 5

# Assignment 5 - Assignment 5 1 Write a program to identify...

This preview shows pages 1–3. Sign up to view the full content.

Assignment 5 1. Write a program to identify the smallest negative number and largest positive number that can be store in a variable of data type “short int”. Your program MUST use while statement (and break if necessary) only for looping. Call this program positive-negative.c. #include <stdio.h> main() { short int i; short int smallest; short int largest; i = 0; do{ smallest = i--; } while(i < 0); largest = i; printf("The smallest possible number is %d. \nThe largest possible number is %d.\n", smallest, largest); } 2. Write a program to check if a given positive integer is a palindrome or not. A palindrome number is one that reads the same forward and backwards. Your program MUST use while statements only. Call this program palindrome-number.c. #include <stdio.h> int main() { int x, y, z, temp; printf("Please enter a positive number: "); scanf("%d", &x); while (x < 0) {

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

View Full Document
printf("Incorrect value, please enter a positive number:"); scanf("%d", &x); } y = x; temp = 0; while (y > 0) { z = y%10; y = y/10; temp = (temp*10) + z; } while (x != temp) { printf("The number you entered is not a palindrome.\n"); return(0); }
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern