tony_lynes_program0.c - scanf"%d"&input...

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

View Full Document Right Arrow Icon
/* *Tony Lynes *Program0, CSCI 112 *2/16/16 */ #include<stdio.h> int main(void) { int max=GetInput(); PrintPattern(max); return(0); } /*Declare integers*/ int PrintPattern(int max){ int i=1; int j=1; int space=0; printf("\n"); for(i=1; i<=max; i=i+2) { /*This for loop implements a # of spaces */ for(space=0; space<=max-i+1; space++) { printf(" "); } for(j=1; j<=i; j++) { printf("%d ", j); } printf("\n"); } for(i=max-2; i>0; i=i-2) { /*This for loop implements spaces before the line*/ for(space=0; space<=max-i+1; space++) { printf(" "); } for(j=1; j<=i; j++) { printf("%d ",j); } printf("\n"); } return 0; } /*Function to get an input from the user and store it as variable*/ int GetInput(void)// recieves starting variables from user */ { int input; int valid=0; printf("Enter an odd number less than or equal to 9 and great than 0 > ");
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: scanf("%d", &input); if(!IsValid(input))/*Will prompt error message if value isnt in domain*/ { input=GetInput(); } return(input); } int IsValid(int x) { if(x<=9 && x>=1 && x%2!=0)/*if is less than equal to 9, and greater than equal to 1 and not even then it will return*/ {//is it ok return 1; } else /*3 main error messages*/ { if(x%2==0)/*If x is even*/ { printf("You have entered an even number. Please try again.\n"); } if(x>9)/*If x is greater than 9*/ { printf("You have entered a number greater than 9. Please try again.\n"); } if(x<1)/*If x is less than 1*/ { printf("You have entered a number less than 1. Please try again.\n"); } printf("\n"); return 0; } }...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern