Examples - Important: I am uploading some examples &...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
Important : I am uploading some examples & TEXT in the C Language for the practice only, some of them we did in the class. Please compile & run ALL the programs, if you find any error during compilation & execution of the program, debug (CORRECT) yourself . Author will not be RESPONSIBLE for any error. Following TEXT & Programs are not official. Programs are not in the order. THESE TEXT AND PROGRAMS ARE NOT FOR COMMERCIAL USE, JUST TO HELP FOR STUDENTS ONLY. Example: #include <stdio.h> int main(void) { int count; for (count = 1; count <= 10; count++) { printf("%d\n",count); } getchar(); getchar(); return(0); } Example: Decrement #include <stdio.h> int main(void) { int count; for (count = 10; count >= 1; count--) { printf("%d\n",count); } getchar(); getchar(); return(0); } 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Example: sum of the series #include <stdio.h> int main(void) { int count,sum = 0; for (count = 10; count >= 1; count--) { printf("%d\n",count); sum = sum + count; } printf("\n The Sum = %d",sum); getchar(); getchar(); return(0); } Example: Print Characters one by One A B C D #include <stdio.h> int main(void) { char letter; for( letter = 'A'; letter <= 'E'; letter = letter + 1 ) { printf("%c ", letter); } getchar(); getchar(); return(0); } Example: just count sum of the series #include <stdio.h> int main(void) { 2
Background image of page 2
{ int total, loop; for( total = 0, loop = 1; loop <= 10; loop = loop + 1 ){ total = total + loop; } printf("Total = %d\n", total ); } getchar(); getchar(); return(0); } Example: Print **** figure #include <stdio.h> int main(void) { int i,j; for (i = 1; i<= 5; i++) { for (j = 1; j<= i; j++) printf("*"); printf("\n"); } getchar(); getchar(); return(0); } OUTPUT * ** *** **** ***** Example: temperature Conversion #include <stdio.h> 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
int main(void) { double cel, fr; for (cel = 5; cel <= 20; cel += 5) { fr = 1.8 * (cel + 32.0); printf("%f s degree is %f Faherenheit degree \n",cel, fr); printf("\n"); } getchar(); getchar(); return(0); } Example: Write a program in to compute the sum of all positive numbers. If number is negative, input will stop and sum of all positive numbers should display. #include <stdio.h> int main(void) { int sum = 0, num,xx; printf("\n Enter a +ve Integer or -ve to quit: "); for(scanf("%d",&num); num> 0; scanf("%d",&num)) { sum = sum + num; printf("\n Enter a +ve Integer or -ve to quit: "); } printf("\n Sum = %d \n",sum); scanf("%d",&xx); getchar(); getchar(); return(0); } 4
Background image of page 4
Example: This program will print the series. #include <stdio.h> int main(void) { int i,n; printf(“\n Input limit : “); scanf("%d",&n); for(i = 0; i < n; i = i+1) { printf("the numbers are %d \n",i); } getchar(); getchar(); return(0); } Example: Draw a box #include <stdio.h> int main(void) { int count = 0; printf("\n**************"); /* box top */ for(count = 1 ; count <= 8 ; ++count) printf("\n* *"); /* box sides */ printf("\n**************\n"); /* bottom of the box */ getchar(); getchar(); return(0); } 5
Background image of page 5

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

View Full DocumentRight Arrow Icon
Example: without initialization #include <stdio.h> int main(void) { int i;
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/03/2009 for the course INDUSTRIAL IE 307 taught by Professor Arzuakyüz during the Spring '09 term at Atılım Üniversitesi.

Page1 / 58

Examples - Important: I am uploading some examples &amp;...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online