Beruflich Dokumente
Kultur Dokumente
Example 1 - C hello world program /* A very simple c program printing a string on screen*/
#include <stdio.h> main() { printf("Hello World\n"); return 0; }
Output of above program: "Hello World" Example 2 - c program to take input from user using scanf
#include <stdio.h> main() { int number; printf("Enter an integer\n"); scanf("%d",&number); printf("Integer entered by you is %d\n", number); return 0; }
Output: Enter a number 5 Number entered by you is 5 Example 3 - using if else control instructions
#include <stdio.h> main() { int x = 1; if ( x == 1 ) printf("x is equal to one.\n"); else printf("For comparison use == as = is the assignment operator.\n"); return 0; }
Above c program prints the number and all arguments which are passed to it.
cout << " Enter temperature in Fahrenheit to convert to degrees Celsius: "; cin >> ftemp;
ctemp = (ftemp-32) * 5 / 9; cout << "Equivalent in Celsius is: " << ctemp << endl;
cout << "Equivalent in Fahrenheit is: " << ftemp << endl; }
#include
<stdio.h> #include <conio.h> void main() { int a; clrscr(); for(i=0; i<5; i++) { printf("\n\t HAI"); } getch(); }
// 5 times
break; case 2: printf("you chose green color\n"); break; case 3: printf("you chose blue color\n"); break; default: printf("you did not choose any color\n"); } return 0; }
Creation Date : 09 Nov 2010 07:44:43 PM Author : www.technoexam.com [Technowell, Sangli] */ #include <stdio.h> #include <conio.h> void main() { int i; clrscr(); for(i=1; i<=10; i++) { if(i==6) continue; printf("\n\t %d",i); } getch(); }
// 6 is omitted
/*
Creation Date : 09 Nov 2010 08:14:00 PM Author : www.technoexam.com [Technowell, Sangli] */ #include <stdio.h> #include <conio.h> void main() { int i=1, j; clrscr(); while(i<=3) { for(j=1; j<=3; j++) { printf(" * "); if(j==2) goto stop; } i = i + 1; } stop: printf("\n\n Exited !"); getch(); }