Example : Simple C Program Template .
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();       // clears the previous output contents from the screen, if any.
	      -----codes------
              -----codes------
              -----codes------
	getch();  // holds output on the screen until user press any key button.Helps in 
                  // displaying the output.
}

/* -------------------------------  OR  ------------------------------------*/

#include<stdio.h>
#include<conio.h>
int main()
{
	clrscr();       // clears the previous output contents from the screen, if any.
	      -----codes------
              -----codes------
              -----codes------
   return 0;  
}
Example : Write a program in c to print a message in different format.
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();        
	printf("Welcome U in ur site codershelpline.com");
	getch();  
}
Output :
Welcome U in ur site codershelpline.com

----------  OR  -----------
#include<stdio.h>
#include<conio.h>
int main()
{
	clrscr();        
	printf("Welcome U in ur site codershelpline.com");	 

        return 0;
}
Output :
Welcome U in ur site codershelpline.com

----------  OR  -----------
#include<stdio.h>
#include<conio.h>
int main()
{
	//clrscr();        
	printf("Welcome U in ur site \"codershelpline.com\" ");	 

        return 0;
}
Output :
Welcome U in ur site "codershelpline.com"
Example : Write a program in c to make a simple calculator.
#include<stdio.h>
#include<conio.h>
void main()
{
	int a,b,add,multi,sub;
	float div;
	
	a=5;
	b=6;
	
	add=a+b;
	multi=a*b;
	sub=a-b;
	div=a/b;
	
	printf("%d%d%d%d%d%f",a,b,add,multi,sub,div);
	getch();
}
/* ----------------------------------  OR  --------------------------------------*/

#include<stdio.h>
#include<conio.h>
void main()
{
	int a,b,add,multi,sub;
	float div;
	
	a=5;
	b=6;
	
	add=a+b;
	multi=a*b;
	sub=a-b;
	div=a/b;
	
	printf("%d\t%d\t%d\t%d\t%d\t%f",a,b,add,multi,sub,div);
	getch();
}
Example : Write a program in c to calculate the area of circle & print them.
#include<stdio.h>
#include<conio.h> 
  void main() 
   { 
     float area,radius; 
     clrscr(); 
     printf("Enter the value for radius: "); 
     scanf("%f",&radius); 
     area=3.14*radius*radius; 
     printf("The Area of Circle is = %f",area);
 
     getch(); 
   }

/* NB: Formula of Area of Circle is = 3.14*r*r    */
Example : Write a program in c to calculate the radius of circle & print them.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
	int area;
	float r;
	printf("Enter area of circle:-");
	scanf("%d",&area);
	r=sqrt(area/3.14);
	printf("%f",r);
	getch();
}

Example : Write a program in c to calculate the area of rectangle & print them.

#include<stdio.h>
#include<conio.h>
 void main()
   {
    int width,height;
    float area;
    clrscr();

    printf("Enter the value of height: ");
    scanf("%d",&height);
    printf("Enter the value of width: ");
    scanf("%d",&width);   
    area= height*width;
    printf("Area of Rectangle is = %f",area);

    getch();
   }

/*  NB: Formula of Area of Rectangle is = height * width    */

Example : Write a program in c to calculate the area of cylinder & print them.

#include<stdio.h>
#include<conio.h> 
   void main() 
    { 
        int radius,height;
	float area; 
        clrscr();
 
        printf("Enter the value of radius: "); 
        scanf("%d",&radius); 
        printf("Enter the value of height:"); 
        scanf("%d",&height); 
        area= 2*3.14*radius*height; 
        printf("The Area of Cylinder is =  %f",area);
 
        getch(); 
    }

/* NB: Formula of Area of Cylinder is =2*3.14*r*h  */

Example : Write a program in c to calculate the area of triangle & print them.

#include<stdio.h> 
#include<conio.h> 
  void main() 
   { 
    int base,height;
    float area; 
    clrscr();
 
    printf("Enter the value of base: "); 
    scanf("%d",&base); 
    printf("Enter the value of height: "); 
    scanf("%d",&height); 
    area= (0.5)*base*height; 
    printf("Area of Trinagle is = %f",area);
 
    getch();
   }
 
/* NB: Formula of Area of Triangle is = 0.5*base*height */

Example : Write a program in c to convert the Celsius value of temperature into Fahrenheit & print them.

#include<stdio.h>
#include<conio.h>

  void main() 
   {
    float fahrenheit,celsius;
    clrscr();

    printf("Enter the value of temperature in celsius: ");
    scanf("%f",&celsius); 
    fahrenheit=1.8*(celsius+32); 
    printf("The temperature in Fahrenheit is =%f",fahrenheit);
 
    getch(); 
   }

/* NB: Formula is fahrenheit = 1.8*(celsius+32);  */ 

Example : Write a program in c to convert the Fahrenheit value of temperature into Celsius & print them.

#include<stdio.h> 
#include<conio.h> 
  void main() 
   { 
    float fahrenheit,celsius; 
    clrscr(); 

    printf("Enter the value of temperature in fahrenheit: "); 
    scanf("%f",&fahrenheit); 
    celsius=0.56*(fahrenheit-32); 
    printf("The value in Celcius is = %f",celsius);
 
    getch(); 
   }

/* NB: Formula is celsius=0.56*(fahrenheit-32);   */

Example : Write a program in c to swap two values using third variables & print them.

#include<stdio.h> 
#include<conio.h> 
  void main() 
   { 
    int a,b,c; 
    clrscr();
 
    printf("Enter the first Value: "); 
    scanf("%d",&a); 
    printf("Enter the second Value: "); 
    scanf("%d",&b);
    printf("The output before swap is: "); 
    printf("%d\t%d",a,b); 
    c=a; 
    a=b; 
    b=c; 
    printf("\nThe output after swap is: "); 
    printf("%d\t%d",a,b);
 
    getch(); 
   } 

Example : Write a program in c to swap two values without using third variables & print them.

#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b,c;
    clrscr();

    printf("Enter the first value :");
    scanf("%d",&a);
    printf("Enter the second value :");
    scanf("%d",&b);
    printf("The result before swapping is :");
    printf("%d\t%d",a,b);
    a=a+b;
    b=a-b;
    a=a-b;
    printf("\nThe output after swapping is :");
    printf("%d\t%d",a,b);

    getch();
}

Example : Write a program in c to print larger value from two values using conditional/ternary operator.

#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
    int a,b; 
    clrscr(); 
    printf("Enter first value :"); 
    scanf("%d",&a); 
    printf("Enter second value :"); 
    scanf("%d",&b); 
    (a>b) ? printf("Frist value %d is larger",a) : printf("Second value %d is larger",b);
 
    getch(); 
} 

Example : Write a program in c to print the largest value from three values using conditional/ternary operator.

#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
    int a,b,c; 
    //clrscr(); 
    printf("Enter first value :"); 
    scanf("%d",&a); 
    printf("Enter second value :"); 
    scanf("%d",&b); 
    printf("Enter third value :"); 
   scanf("%d",&c); 
   ((a>b) && (a>c)) ? printf("First value %d is largest",a):((b>c)&&(b>a)) ? printf("Second value %d is largest",b):printf("Third value %d is largest",c); 
    getch(); 
} 

Example : Write a program in c to print the year, month and day value from given  total days .

#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
    int day,month,year; 
    clrscr(); 
    printf("Enter the value for total days:"); 
    scanf("%d",&day);
	 
    year=day/365; 
    day=day%365; 
    
    month=day/30; 
    day=day%30;
	 
    printf("\nYear = %d \nMonth = %d \nDay = %d",year,month,day); 
    getch(); 
} 

Example : Write a program in c to print the square root of given values .

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
   int num; 
   float result;    
   printf("Enter a number: ");
   scanf("%d",&num);	
   result=sqrt(num);
   printf("%f",result);   
   getch();
}

Example : A C program to calculate compound interest of given values .

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
	int p,r,t;
	float ci;
	p=1000;
	r=20;
	t=3;
	ci=p*pow((1+r/100),t);
	printf("%f",ci);
	getch();
}

Example : A C program to convert lower case character to upper case and its vice-versa  of given values  using C function.

#include<stdio.h>
#include<ctype.h>

int main()
{
   char c1='a';
   char c2='A';
   printf("%c\n",tolower(c1));
   printf("%c",toupper(c2));
   return 0;
}

Example : A C program can be compiled without main function.

#include<stdio.h>    
#define start main    
void start() 
{    
   printf("Codershelpline.com");    
}    

Example : A C program to print message without using semi colon.

#include<stdio.h>      
void main()
{      
	 if(printf("Codershelpline"))
	 { }  
}    

 751 total views,  1 views today

Categories: C

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.