0% found this document useful (0 votes)
14 views14 pages

Devi C File-1

The document contains ten C programs demonstrating various programming concepts such as printing 'Hello World', calculating simple interest, displaying data types and their ranges, computing employee salary with allowances, finding the largest of three numbers, checking roots of a quadratic equation, performing basic arithmetic operations based on user choice, summing the first ten natural numbers, generating Fibonacci series, and finding the maximum element in an array. Each program includes code snippets and expected outputs. The programs serve as practical examples for learning C programming.

Uploaded by

drjas.cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views14 pages

Devi C File-1

The document contains ten C programs demonstrating various programming concepts such as printing 'Hello World', calculating simple interest, displaying data types and their ranges, computing employee salary with allowances, finding the largest of three numbers, checking roots of a quadratic equation, performing basic arithmetic operations based on user choice, summing the first ten natural numbers, generating Fibonacci series, and finding the maximum element in an array. Each program includes code snippets and expected outputs. The programs serve as practical examples for learning C programming.

Uploaded by

drjas.cse
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Program 1.

C-program to print’ Hello World’

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("hello world!");
getch();
}

OUTPUT
Program.2- C-Program to calculate simple interest
#include<stdio.h>
#include<conio.h>
void main()
{
float P,R,T,SI;
clrscr();
printf("enter the value of P,R,T\n");
scanf("%f %f %f",&P,&R,&T);
SI=P*R*T/100;
printf("simple interest is %f",SI);
getch();
}

OUTPUT-
Program-3 C-Program to print data types and their range.
#include<stdio.h>
#include<conio.h>
#include<limits.h>
void main()
{
clrscr();
printf("\nsize of integer in bytes %d",sizeof(int));
printf("\nsize of long integer in bytes %d",sizeof(long int));
printf("\nsize of char in bytes %d",sizeof(char));
printf("\nsize of float in bytes %d",sizeof(float));
printf("\nsize of double in bytes %d",sizeof(double));
printf("\nminimum range for integer %d",INT_MIN);
printf("\nmaximum range for integer %d",INT_MAX);
printf("\nminimum range for char %d",CHAR_MIN);
printf("\nmaximum range for char %d",CHAR_MAX);
getch();
}
OUTPUT-
Program-4 C-Program to accept basic salary of an employee.Compute DA as 20% of basic
salary and HRA as 15% of basic salary. If basic salary >= 15000 else compute DA as 15%
and HRA as 20% of basic salary .Display total salary as sum of basic salary,HRA and DA.
#include<stdio.h>
#include<conio.h>
void main()
{
int salary;
float DA,HRA,TOTAL;
clrscr();
printf("\nenter the salary");
scanf("%d",&salary);
if(salary>=15000)
{
DA= 0.2*salary;
HRA=0.15*salary;
printf("DA=0.20*salary %f\n",0.2*salary);
printf("HRA=0.15*salary %f",0.15*salary);
}
else
{
DA=0.15*salary;
HRA=0.10*salary;

printf("DA=0.15*salary %f\n",0.15*salary);
printf("HRA=0.10*salary %f",0.10*salary);
}
TOTAL=salary+DA+HRA;
printf("TOTAL=salary+DA+HRA %f",TOTAL);
getch();
}
OUTPUT-
Program.5- C-Program to input three numbers and display largest of three umbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter the threee numbers");
scanf("%d %d %d",&a,&b,&c);
if(a>b&&a>c)
printf("%d is greater than %dand%d",a,b,c);
else
if(b>a&&b>c)
printf("%d is greater than %d and %d",b,a,c);
else
printf("%d is greater than %d and%d",c,a,b);
getch();

OUTPUT-
Program.6- C-Program to check whether roots of a quadratic equation are real and
unequal, real and equal, imaginary.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a,b,c,D;
float x1,x2;
clrscr();
printf("enter value of a,b,c");
scanf("%d %d %d",&a,&b,&c);
D=b*b-4*a*c;
if(D>0)
{
printf("roots are real and unequal");
x1=(-b+sqrt(D))/2*a;
x2=(-b-sqrt(D))/2*a;
printf("%f %f",x1,x2);
}
else
if(D<0)
{
printf("roots are real and equal ");
x1=(-b/2*a);
x2=(-b/2*a);
printf("%f %f",x1,x2);
}
else
{
printf("roots are imaginary");
x1=(-b+sqrt(D))/2*a;
x2=(-b-sqrt(D))/2*a;
printf("%f %f",x1,x2);
}
getch();
}
OUTPUT-
Program 7. C-Program to print menu and compute sum,subtraction,multiplication,division
of two numbers depending upon users choice.
#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,sum,product,subtraction,div;
int ch;
clrsc#include<stdio.h>
r();
printf("1 addition\n");
printf("2 product\n");
printf("3 difference\n");
printf("4 division\n");
printf("enter the numbers");
scanf("%d %d",&n1,&n2);
printf("enter the choice");
scanf("%d",&ch);
switch(ch)
{case 1:
sum =n1+n2;
printf("sum is %d",sum);
break;
case 2:
product=n1*n2;
printf("product is %d",product);
break;
case 3:
subtraction=n1-n2;
printf("subtraction is %d",subtraction);
break;
case 4:
div=n1/n2;
printf("division is %d",div);
break;
default:printf("enter choices is mismatching");
}
getch
OUTPUT-
1. When choice is subtraction-

2. When choice is product


Program 8-C – Program to print sum of first ten natural numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1,sum=0;
clrscr();
while(i<=10)
{
sum=sum+i;
i++;
}
printf("sum of first ten natural number is %d",sum);
getch();
}

OUTPUT-
Program.9- C-Program to print Fibonacci series upto n terms.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,t,a,b,c;
clrscr();
printf("enter the number of terms");
scanf("%d",&n);
a=0;b=1;
printf("\n %d\t%d",a,b);
for(t=3;t<=n;t++)
{
c=a+b;
printf("\t%d",c);
a=b;
b=c;
}
getch();
}

OUTPUT-
Program.10 C-Program to store ten elements in an aaray . Display maximum element from
list.
#include<stdio.h>
#include<conio.h>
void main()
{
int element[10],i,large;
clrscr();
for(i=0;i<10;i++)
{
printf("enter element %d",i+1);
scanf("%d",&element [i]);
}
i=0;
large=element[i];
while(i<10)
{
if (large<element[i])
large=element[i];
i++;
}
printf("largest element =%d",large);
getch();
}
OUTPUT-

You might also like