notes2

N num1 else printf d is not divisible by 7n

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: begins program execution */ int main() { int num1; /* declare variables */ printf( "\nEnter an integer, and I will tell you\n" ); printf( "if it is divisible by 7: " ); scanf( "%d", &num1 ); /* read integer */ if ( num1 % 7 == 0 ){ printf( "%d is divisible by 7.\n", num1 ); } else { printf( "%d is not divisible by 7.\n", num1 ); } return 0; /* indicate that program ended successfully */ } /* end function main */ C Program: nested if…else 1 2 3 4 5 6 7 8 9 10 11 12 13 /* using nested if...else statements*/ #include <stdio.h> /* function main begins program execution */ int main() { int score; /* declare variables */ printf( "\nEnter your score, and I will tell you\n" ); printf( "your grade: " ); scanf( "%d", &score ); /* read integer */ C Program: nested if…else if ( score >= 90 ) 14 printf( "You got an A.\n" ); 15 else 16 if ( score >= 80 ) 17 printf( "You got a B.\n" ); 18 else 19 if ( score >= 70 ) 20 printf( "You got a C.\n" ); 21 else 22 if ( score >= 60 ) 23 printf( "You got a D.\n" ); 24 else 25 printf( "You got an F.\n" ); 26 27 return 0; /* indicate that program ended successfully */ 28 29 30 } /* end function main */ C Program:...
View Full Document

This note was uploaded on 03/02/2009 for the course ENGR 3 taught by Professor Ben-yaakov during the Fall '08 term at UCSB.

Ask a homework question - tutors are online