Introduction

C is a basic language to learn the programming. Actually what is meaning of programming. Programming means input of row material, which gives us the magical statue of output on which we can ride a long journey of programming. Before c language, many
Language written such as…
COBAL
FORTRAN
ALGOL 60
CPL
BCPL
PASCAL…(etc)
B and bcpl was very close to c, because the co-worker of Dennis Ritchee wrote it. Dennis studied those languages and made advance version of them. Which afterwards
Famous as c language
Getting c started
We have known to learn any language we first know about alphabets, keywords, and special symbols. Same way in c language also we have to know
Those things in c also.
Alphabets… A, B, C… X, Y, Z
a, b, c……x, y, z
Digits… 1,2,3,4,5,6,7,8,9
Special symbols… ~, !, @,#,$,%,^,&,*,(,),_,-,+,=,|,\,{,[
},],:,;,”,’,<,,,>,.,?,/
Types of c constants
Primary constants
1) Integer constants
2) Real constant
3) Character constant
Secondary constant
1) Array
2) Pointer
3) Structure
4) Union
5) Enum
Data Types
1) Integer,
2) Character,
3) Float,
4) Double…(etc)
lets know what we say to special symbols
1)’~’= approximately equal to.
2)’! =’= Is not equal to.
3)’@’= at the rate.
4)’#’= hash.
5)’$’=
6)’^’=
7)’&&’= and.
8)’!!’= Or.
9)’{’= open curly brasses.
10)’}’= close curly brasses.
How to compile and run the program
Short way to compile Alt + F9 and to run the program Ctrl + F9 should press.
let’s start our Some basic programs
Any comment we have to write in /**/ these pattern.
Syntax of simple programs
#include<stdio.h> /*header file/
#include<conio.h> /*header file/
void main()
{
clrscr();
/*any opration*/
getch();
}
These is the basic syntax of any programs the topic changes some data add in these but syntax remain constant.
/*simple print hello pune statement */
#include<stdio.h> /*header file */
#include<conio.h> /*header file */
void main()
{
printf(“\nhello pune”)/ \*n = new line */
getch();
}
Output = “hello pune”
In these program we just print simple statement hello pune which have been written in printf statement (line no 5).
Integer data type
Integer data type include the number such as 1,2,3,4,5,6,7,8,9…
1)/*addition type program through keyboard/…(comment)
#include<stdio.h> /*header file */
#include<conio.h> /*header file */
void main()
{
int a,b,c; /*integer data type */
clrscr();
printf(“enter the nos”);
scanf(“%d%d”,&a,&b);
c=a+b; /*operation */
printf(“\n%d”,c);
getch();
}
Output = enter two value through keyboard you will get addition
of them.
In these program we have taken 3 integer variable, in these program we have to enter 2 values from keyboard and it will show us the addition of these, because we have perform the operation at line no 9.
/*Addition type without keyboard/
#include<stdio.h> /*header file */
#include<conio.h> /*header file */
void main()
{
int a=3,b=5,c; /*integer data type */
clrscr();
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“\n%d%d”,a,b);
getch();
}
Output = you will get addition of 3&5=8.
In these program we have taken 3 integer variables for these we have taken the value of them in program itself, c variable use to do the addition operation.
Character data type
Character data type include the alphabets…A, B, C…X, Y, Z. and a, b, c…x, y, z.
1)/*multiplication using keyboard */
#include<stdio.h> /*header file */
#include<conio.h> /*header file */
void main()
{
char ‘a’; /*character data type */
clrscr();
scanf(“%c”,&a);
printf(“\n%c”,a);
getch();
}
Output = type any alphabet, that will display again.
In these program we have taken only one character and we have to put these value of that constant. And it will print again. Any single character we have to write in single cotton (‘a’).
Float data type
Float is one of the data type in which we have to enter only numbers which include decimal points. Such as 111.23,14.12,11.00 etc. Though you takes value without decimal point it will also consider, such as if we write value as 112 it will display as 112.00 which means as these value include decimal point.
#include<stdio.h>/*header file */
#include<conio.h>/*header file */
void main()
{
float a,b,c;
clrscr();
printf*(“\nenter the nos”);
scanf(“%f%f%f”,&a,&b,&c);
c=a-b;
printf(“\nc=%d”,c);
getch();
}
Output = subtraction of a and b.
In these program we have to take two such values such as it should contain decimal point. After compiling these c will perform subtraction operation.
/*To calculate the gross salary, of any person whose dearness allowance is 60% of basic salary, and house rental allowance is 40% of basic salary. And basic salary is input */
#include<stdio.h> /*header file */
#include<conio.h> /*header file */
void main()
{
float basic p,da,grpay,hra; /*float data type */
clrscr();
printf(“\nenter the nos”);
scanf(“%f”,&basic p);
da=0.6*basic p; /*operation */
hra=0.4*basic p; /*operation */
grpay=basic p+da+hra; /*operation */
printf(“\n%f”,da);
printf(“\n%f”,hra);
printf(“\n%f”,grpay);
getch();
}
Output = In these program we have to enter the basic salary through keyboard and you will get gross salary.
In these program we have taken basic salary as input and after that da, hra, grpay, are calculated by formula.
/*The distance between two cities (in km) is input through keyboard
Write a program to convert and print these numbers in to meter, inches and centimeter */
#include<stdio.h> /*header file */
#include<conio.h> /*header file */
void main()
{
float km,m,cm,inches,ft; /*float data type */
clrscr();
printf(“\nenter the distance in km”);
scanf(“%f”,&km);
m=km*1000; /*operation */
cm=m*100; /*operation */
inches=m/2.54; /*operation */
ft=inches/12; /*operation */
printf(“ \n%f”,m);
printf(“\n%f”,cm);
printf(“\n%f”,inches);
printf(“\n%f”,ft);
getch();
}
Output = suppose you have enter distance in km is 1000,then distance in m=1000000,cm=100000000,inches=40000000,ft=3333333.25,will found as we done in operation.
/*If marks obtain by a student in five subjects. Calculate the average and percentage. Consider that all marks out of 100*/
#include<stdio.h> /*header file */
#include<conio.h> /*header file */
void main();
{
int a,b,c,d,e,avg; /*float data type */
float per;
clrscr(); /*float data type */
printf(“enter the marks of subjects”);
scanf(“%d%d%d%d%d”,&a,&b,&c,&d,&e);
avg=a+b+c+d+e; /* operation */
per=avg/5; /* operation */
printf(“%d%f”,avg,per);
getch();
}
Output = suppose we enter the marks of subject just as 77,66,55,69,72,then the avg=339and per=67.00.
5)/*Temperature of a city in Fahrenheit degree is input through the keyboard.Write a program to convert these temperature into centigrade degree */
#include<stdio.h>
#include<conio.h>
void main()
{
float fr,cent;
clrscr();
printf(“enter the temperature in farad”);
scanf(“%d”,&fr);
cent=5.0/9.0*(fr-32);
printf(“temperature in centigrade=%f”,cent);
getch();
}
Output = suppose you have enter the temperature in centigrade is 200 then the temperature in fr will be 93.33.
6)/*length & breadth of a rectangle and radius of circle are input through the keyboard. Write a program to calculate the area &perimeter of the area & circumference of the circle */
#include<stdio.h>
#include<conio.h>
void main();
{
int l,b,r,area1,perimeter;
float area2,circum; /*float data type */
clrscr(); /*float data type */
printf(“enter the length & breadth of rentangle”);
scanf(“%d%d”,&l,&b);
area1=l*b; /*aea of rentangle */
perimeter = 2*l+2*b; /*perimeter of rentangle*/
printf(“area of rentangle =%d”,area);
printf(“perimeter of rentangle =%d”,perimeter);
printf(/n/nenter the radius of circle);
area2=3.14*r*r;/*area of circle*/
circum=2*3.14*r;/*circumference of circle*/
printf(“area of circle =%d”,area2);
printf(“circumstance of circle =%d”,circumstance);
getch();
}
Output =
7)Two numbers are input through the keyboard into two locations c and d write a program to interchange thee contents of c and d
#include<stdio.h>
#include<conio.h>
void main();
{
int l,b,r;
clrscr();
printf(“enter the number at location l and b”);
scanf(“%d%d”,&l,&b);
r=b;
b=l;
l=r;
printf(“value of c =%d”,c);
printf(“value of d=%d”,d);
getch();
}
Write a program to calculate the sum of its digits in which the entering numbers are input through keyboard.
#include<stdio.h>
#include<conio.h>
void main();
{
int a,b,num,sum;
clrscr();
printf(“enter the numbers ”);
scanf(“%d”,&num);
a=num%10;
n=num/10;
sum=sum+a;
a=num%10;
n=num/10;
sum=sum+a;
a=num%10;
n=num/10;
sum=sum+a;
a=num%10;
n=num/10;
sum=sum+a;
a=num%10;
sum=sum+a;
printf(“the sum of five digits of%d is %d”,num,sum);
getch();
}
9)/*Write a program to reverse the five digit number*/
#include<stdio.h>
#include<cono.h>
void main();
{
int a,b,n;
int revnum;
clrscr();
printf(“enter the numbers ”);
scanf(“%d”,&n);
a=n%10;
n=n/10;
revnum=revnum+10000;
a=n%10;
n=n/10;
revnum=revnum+1000;
a=n%10;
n=n/10;
revnum=revnum+100;
a=num%10;
n=num/10;
revnum=revnum+10;
a=num%10;
revnum=revnum+a;
printf(“the reverse number is %d”,revnum);
getch();
}