DOTE TNDTE C Programming LAB
DOTE TNDTE C Programming LAB
DOTE TNDTE C Programming LAB
Prepared by tptmagendiranatgmaildotcom
Page 1
2. Write C language program to find whether the given number is a positive number, negative
number or zero.
#include<stdio.h>
#include<conio.h>
void main()
{
int number;
clrscr();
printf ("Enter the number \n");
scanf ("%d", & number);
if (number >0)
{
printf ("number is positive \n");
}
else if (number <0)
{
printf ("number is nagative \n");
}
else
{
printf ("number is zero \n");
}
getch();
}
OUTPUT
Enter the number
8
number is positive
Enter the number
-8
number is nagative
Enter the number
0
number is zero
Prepared by tptmagendiranatgmaildotcom
Page 2
3. Write C language program to find the sum of series using While loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i=1, sum=0;
clrscr();
printf ("Enter The Value of \n");
scanf ("%d", & n);
printf ("first % d numbers are \n",n);
while (i<=n)
{
printf ("%d",i);
sum=sum+i;
i++;
}
printf ("\n sum=%d \n",sum);
getch();
}
OUTPUT
Enter The Value of
10
first 10 numbers are
12345678910
sum=55
Prepared by tptmagendiranatgmaildotcom
Page 3
4. Write C language program to perform the Arithmetic operation based on the numeric key press
using switch case statement. (1-Addition, 2-Subtraction, 3 multiplication, 4 - Division).
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int choice;
float a,b,c;
clrscr();
printf ("Enter The 2 Numbers \n");
scanf ("%f%f",&a,&b);
printf ("\n 1 Add 2 Sub 3 Mul 4 Div \n");
printf ("Enter The Choice \n");
scanf ("%d",& choice);
switch (choice)
{
case 1:
c= a+b;
break;
case 2:
c= a-b;
break;
case 3:
c= a*b;
break;
case 4:
c= a/b;
break;
defalut : printf ("wrong choice !!! \n Press any Key");
}
getch();
printf("\n Result= %f",c);
getch();
}
Prepared by tptmagendiranatgmaildotcom
Page 4
OUTPUT
Prepared by tptmagendiranatgmaildotcom
Page 5
Prepared by tptmagendiranatgmaildotcom
Page 6
Prepared by tptmagendiranatgmaildotcom
Page 7
7. Write C language program to prepare the total marks for N students by reading the Name,
Reg.No, Marks 1 to Marks 6 using array of structure.
#include<stdio.h>
#include<conio.h>
struct student
{
int i,j,regno;
char name [20];
int mark [20];
int total;
};
void main ()
{
struct student s[100];
int i,j,n;
clrscr ();
printf ("\n Enter the number of student \n");
scanf ("%d",&n);
for(i=0;i<n;i++)
{
printf ("\n Enter the register number, name and 6 marks one by
one \n");
scanf ("%d%s",&s[i].regno,s[i].name);
for(j=0;j<=5;j++)
{
scanf("%d",&s[i].mark[j]);
}
}
printf("\n*******************************************");
printf("\n GPT KRISHNAGIRI");
printf("\n Number\t Name\t TotalMarks");
printf("\n*******************************************\n");
for(i=0;i<n;i++)
{
s[i].total=0;
for(j=0;j<6;j++)
{
s[i].total=s[i].total+s[i].mark[j];
}
printf("%d\t%s\t%d\n",s[i].regno,s[i].name,s[i].total);
}
getch();
}
Prepared by tptmagendiranatgmaildotcom
Page 8
OUTPUT
Prepared by tptmagendiranatgmaildotcom
Page 9
Prepared by tptmagendiranatgmaildotcom
Page 10
9. Write C language program to calculate the equivalent resistance of three resistances connected
in series and parallel.
#include<stdio.h>
#include<conio.h>
void main()
{
float r1,r2,r3,rs,rp;
clrscr();
printf ("Enter The Resistance r1,r2,r3: \n");
scanf ("%f%f%f", &r1,&r2,&r3);
rs=r1+r2+r3;
rp=1/(1/r1+1/r2+1/r3);
printf ("\n Equivalent resistance in series: %f",rs);
printf ("\n Equivalent resistance in parallel: %f",rp);
getch();
}
Output
Enter The Resistance r1,r2,r3:
246
Equivalent resistance in series: 12.000000
Equivalent resistance in parallel: 1.090909
10. Write C language program to calculate the equivalent Capacitance of three Capacitors
connected in series and parallel.
#include<stdio.h>
#include<conio.h>
void main()
{
float c1,c2,c3,cs,cp;
clrscr();
printf ("Enter The Capacitance c1,c2,c3: \n");
scanf ("%f%f%f", &c1,&c2,&c3);
cs=1/(1/c1+1/c2+1/c3);
cp=c1+c2+c3;
printf ("\n Equivalent Capacitance in series: %f",cs);
printf ("\n Equivalent Capacitance in parallel: %f",cp);
getch();
}
Output
Page 11
11. Write C language program to find Resonant Frequency of RLC Series and Parallel Circuits.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float R,L,C,fs,fp;
clrscr();
printf ("Enter The R,L,C: \n");
scanf ("%f%f%f", &R,&L,&C);
fs=1/(2*3.14*sqrt(L*C));
fp=1/(2*3.14*sqrt(1/L*C)-pow(R/L,2));
printf ("\n Resonant frequency in series: %f",fs);
printf ("\n Resonant frequency in parallel: %f",fp);
getch();
}
Output
Enter The R,L,C:
246
Resonant frequency in series: 0.032504
Resonant frequency in parallel: 0.134383
12. Write C language program to find the power factor of series RL circuits.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float R,L,XL,F,Z,pf;
clrscr();
printf ("\n Enter The R,L,F:");
scanf ("%f%f%f",&R,&L,&F);
XL=2*3.14*F*L;
Z=sqrt(R*R+XL*XL);
pf=R/Z;
printf ("\n Power Factor in Series: %f",pf);
getch();
}
Output
Enter The R,L,F:
246
Power Factor in Series: 0.013268
Prepared by tptmagendiranatgmaildotcom
Page 12
13. Write C language program to find the Q factor for series and parallel resonant circuits.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float R,L,C,F,qfs,qfp;
clrscr();
printf ("Enter The R,L,C,F: \n");
scanf ("%f%f%f%f", &R,&L,&C,&F);
qfs=1/R*sqrt(1/C);
qfp=(2*3.14*F)/R;
printf ("\n Q FACTOR in series: %f",qfs);
printf ("\n Q FACTOR in parallel: %f",qfp);
getch();
}
Output
Enter The R,L,C,F:
2462
Q FACTOR in series: 0.204124
Q FACTOR in parallel: 6.280000
14. Write C language program to draw the symbol of NPN transistor using Graphics.
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd = DETECT, gm;
initgraph(&gd,&gm, "c:\\tc\\bgi");
line(100, 100, 100, 200);
line(70, 150, 100, 150);
line(100, 125, 150, 90);
line(100, 175, 150, 210);
line(140, 190, 150, 210);
line(130, 210, 150, 210);
outtextxy(100, 250, "NPN Transistor");
getch();
closegraph();
}
Prepared by tptmagendiranatgmaildotcom
Page 13
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm, "c:\\tc\\bgi");
printf("C language program to draw the symbol of Diode using Graphics \n");
line(200,200,200,400);
line(140,300,200,300);
line(200,200,300,300);
line(200,400,300,300);
line(300,200,300,400);
line(300,300,500,300);
getch();
closegraph();
}
Prepared by tptmagendiranatgmaildotcom
Page 14