C TUTORIAL

Link To Download Turbo C++

1.Simple C Program To Read and Print a Integer Number

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main()// entrance of program execution
{
int a; // declaration of variables
clrscr();// this function is for clearing the screen , this is from conio.h
printf(“Enter a value”);//this function prints value on console
scanf(“%d”,&a);//this function scans one integer input from console
printf(“result is%d”,a);
getch();// this function waits for user input of any key to continue further.
}

2.Simple C Program To Read and Print a Float Number

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main()
{
float a;
clrscr();
printf(“Enter a value”);
scanf(“%f”,&a);
printf(“result is%f”,a);
getch();
}

3.Simple C Program To show the use of unary (pre increment)operator

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
float a;
clrscr();
printf(“Enter a value”);
scanf(“%f”,&a);
printf(“result is%f\n”,a);
printf(“result after%f\n”,++a);
printf(“result later is%f\n”,a);
getch();
}

Operators In C Programming

4.Simple C Program To show the use of unary (post increment)operator

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
float a;
clrscr();
printf(“Enter a value”);
scanf(“%f”,&a);
printf(“result is%f\n”,a);
printf(“result after%f\n”,a++);
printf(“result later is%f\n”,a);
getch();
}

5.Simple C Program To show the use of binary (arithmetic) operator

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main()
{
float a,b,c;
clrscr();
printf(“Enter two values”);
scanf(“%f%f”,&a,&b);
c=a+b;
printf(“\nSum=%f”,c);
getch();
}

6.Simple C Program To show the use of ternary operator

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main()
{
float a,b;
clrscr();
printf(“Enter two values”);
scanf(“%f%f”,&a,&b);
(a>b)?printf(“a is greater”):printf(“b is greater”);
getch();
}

Control Statements In C Programming

7.Simple C Program To show the use of if else control structure

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a,b;
clrscr();
printf(“Enter two values”);
scanf(“%d%d”,&a,&b);
if(a>b)
printf(“\nA is greater”);
else
printf(“\nB is greater”);
getch();
}

8.Simple C Program To show the use of if else if control structure

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a,b,c;
clrscr();
printf(“Enter three values”);
scanf(“%d%d%d”,&a,&b,&c);
if((a>b)&&(a>c))
printf(“\nA is greater”);
else if(b>c)
printf(“\nB is greater”);
else
printf(“\nC is greater”);
getch();
}

9.Simple C Program To show the use of switch control structure

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a,b,c,res=0;
clrscr();
printf(“Enter two values”);
scanf(“%d%d”,&a,&b);
printf(“\nenter your choice”);
scanf(“%d”,&c);
switch(c) {
case 1:res=a+b;
printf(“Sum=%d”,res);
break;
case 2:res=a-b;
printf(“Sub=%d”,res);
break;
default:printf(“No Case Matched”);
}
getch();
}

10.Simple C Program To show the use of for loop

#include #include
main() {
int i=0;
clrscr();
for(i=0;i<10;i++)
printf(“%d\n”,i);
getch();
}

11.Simple C Program to print odd and even numbers separately using for loop.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int i=0;
clrscr();
for(i=0;i<10;i++)
{
if(i%2==0)
printf(“%d\n”,i);
else
printf(“\t%d\n”,i);
}
getch();
}

12.Simple C Program to show the use of while loop.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a,b;
clrscr();
printf(“enter two values”);
scanf(“%d%d”,&a,&b);
while(a<b) {
printf(“a=%d\n”,a);
a++;
}
getch();
}

13.Simple C Program to show the use of do while loop.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a,b;
clrscr();
printf(“enter two values”);
scanf(“%d%d”,&a,&b);
do {
printf(“a=%d\n”,a);
a++;
}while(a<b);
getch();
}

Functions In C Programming

14.Simple C Program to show the use of function with no arguments and no return values.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
clrscr();
drawFun();
displayhi();
drawFun();
getch();
}
displayhi() {
printf(“HELLO WELCOME\n”);
}
drawFun() {
printf(“—————\n”);
}

15.Simple C Program to show the use of function with arguments and no return values.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a,b,c;
clrscr();
printf(“enter two values\n”);
scanf(“%d%d”,&a,&b);
add(a,b);
getch();
}
add(a,b) {
printf(“SUM=%d”,(a+b));
}

16.Simple C Program to show the use of function with arguments and with return values.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a,b,c;
clrscr();
printf(“enter two values\n”);
scanf(“%d%d”,&a,&b);
c=add(a,b);
printf(“SUM=%d”,c);
getch();
}
int add(m,n)
{
return(m+n);
}

17.Simple C Program to show the use of recursive function.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a,res=0;
clrscr();
printf(“enter a value\n”);
scanf(“%d”,&a);
res=add(a);
printf(“RES=%d”,res);
getch();
}
int add(m)
{
if(m==1 || m==0)
return 1;
else
return (m+add(m-1));
}

18.Simple C Program to show the use reading and printing array.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a[10],i,n;
clrscr();
printf(“enter n\n”);
scanf(“%d”,&n);
printf(“enter %d values\n”,n);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
printf(“entered %d values are\n”,n);
for(i=0;i<n;i++)
printf(“%d”,a[i]);
getch();
}

19.Simple C Program to show the use reading and performing sum of array.

#include<stdio.h>//standard input output.headerfile
#include<conio.h>//console input output .headerfile

main() {
int a[10],i,n,sum=0;
clrscr();
printf(“enter n\n”);
scanf(“%d”,&n);
printf(“enter %d values\n”,n);
for(i=0;i<n;i++)
scanf(“%d”,&a[i]);
for(i=0;i<n;i++)
sum=sum+a[i];
printf(“sum=%d”,sum);
getch();
}