the file content the program based on
addition,substraction,division,multiplication
array-ascending and descending
logical and to find largest and smallest
nestest if..else to find largest and smallest
loops
check the given no. is prime or not
sum of some series
and etc...
2. /*c-program to find largest among three nos.
using logical AND*/
#include<stdio.h>
#include<conio.h>
void main ()
{
int a,b,c;
printf("Enter values of a, b and c");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(a>c))
printf("%d is largest",a);
if((c>a)&&(c>b))
printf("%d is largest",c);
getch();
}
/*close of main()function*/
/*output */
Enter values of a, b and c1 2 3
3 is largest
Enter values of a, b and c7 8 9
9 is largest
Enter values of a, b and c11 15 23
23 is largest
Enter values of a, b and c1 6 9
9 is largest
3. /*c-program for finding the sum of series
of 1 to 1/(10!)*/
#include<stdio.h>
#include<conio.h>
void main()
{
float i,sum,fact;
for(i=1,sum=0,fact=1;i<=10;i++)
{
fact=fact*i;
sum=sum+(1/fact);
}
printf("sum=%f",sum);
getch();
}
/*output*/
sum=1.718282
4. /*c program to find sum of(1/1) to
(1/10)*/
#include<stdio.h>
#include<conio.h>
void main()
{
float i,sum;
for(i=1,sum=0;i<=10;i++)
{
sum=sum+(1/i);
}
printf("sum=%f",sum);
getch();
}
/*output*/
sum=2.928968
5. /*c program for addition of1-5 numbers
using while loop*/
#include<stdio.h>
#include<conio.h>
void main()
{
int sum=0,i=1;
while(i<=5)
{
sum=sum+i;
i++;
}
printf("addition=%d",sum);
getch();
}
/*output*/
addition=15
/* c-program to find table from 1 to 10*/
#include<stdio.h>
8. #include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter the values of a,b,c");
scanf("%d%d%d", &a,&b,&c);
if(a>c)
{
if(a>c)
printf("%d is largest",a);
else
printf("%d is largest",c);
}
else
{
if(b>c)
printf("%d is largest",b);
else
printf("%d is largest",c);
}
getch();
}
/*output*/
enter the values of a,b,c
1 4 0
4 is largest
enter the values of a,b,c
3 4 5
5 is largest
9. /*c-program for addition oftwo nos.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter the values of a&b");
scanf("%d%d",&a,&b);
c=a+b;
printf("Addition=%d",c);
getch();
}
/*output*/
Enter the values of a&b90 10
Addition=100
Enter the values of a&b56 75
Addition=131
10. /*c-program for Division oftwo nos.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the values of a&b");
scanf("%d%d",&a,&b);
c=a/b;
printf("Division=%d",c);
getch();
}
/*output*/
Enter the values of a&b10 10
Division=1
Enter the values of a&b 70 10
Division=7
11. /*c-program for Subtraction of two
nos.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the values of a&b");
scanf("%d%d",&a,&b);
c=a-b;
printf("Subtraction=%d",c);
getch();
}
/*output*/
Enter the values of a&b56 45
Subtraction=11
12. /*c-program for multiplication oftwo
nos.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the values of a&b");
scanf("%d%d",&a,&b);
c=a*b;
printf("Multiplication=%d",c);
getch();
}
/*output*/
Enter the values of a&b10 10
Multiplication=100
Enter the values of a&b90 90
Multiplication=8100
13. /*c-program to find area of circle*/
#include<stdio.h>
#include<conio.h>
void main()
{
int r,pie=3.14,a;
clrscr();
printf("Enter the values of r");
scanf("%d",&r);
a=3.14*r*r;
printf("Area of circle=%d",a);
getch();
}
/*output*/
Enter the values of r10
Area of circle=314
14. /*c-program for conditional branching of
switch as well as to show break statment*/
#include<stdio.h>
#include<conio.h>
int main()
{
int n;
clrscr();
printf("enter no.=");
scanf("%d",&n);
switch(n);
{
case0:printf("zero");
break();
case1:printf("one");
break();
case2:printf("two");
break();
default:printf("Invalid Input");
break();
}
getch();
}
/*output*/
enter no.=1
one
enter no.=2
two
enter no.=0
zero
15. /*c-program to find whether the integer is odd
or even*/
#include<stdio.h>
#include<conio.h>
int main()
{
int n; //n is any integer
printf("Enter the value of n");
scanf("%d",&n);
//True if remainder is 0
if(n%2==0)
printf("%d is an even integer",n);
else
printf("%d is an odd integer",n);
getch();
}
/*output*/
Enter the value of n7
7 is an odd integer
Enter the value of n10
10 is an even integer
Enter the value of n1
1 is an odd integer
Enter the value of n0
0 is an even integer
16. /*c-program to find smallest among the three nos.
using nested if..else or if else laddar*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("Enter the values of a,b,c");
scanf("%d%d%d",&a,&b,&c);
if(a<b)
{
if(a<c)
printf("%d is smallest",a);
else
printf("%d is smallest",c);
}
else
{
if(b<c)
printf("%d is smallest",b);
else
printf("%d is smallest",c);
}
getch();
}
/*output*/
Enter the values of a,b,c1 4 7
1 is smallest
Enter the values of a,b,c 0 1 9
0 is smallest
Enter the values of a,b,c991 198 90
90 is smallest
17. /*C-program to write array elements in descending order.*/
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,j,k;
printf("Enter the array elements:");
for(i=0;i<10;i++)
{
scanf("%dt",&a[i]);
}
for(i=0;i<9;i++) /*write array elements in
descending order*/
{
for(j=i+1;j<10;j++)
{
if(a[i]<a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
}
printf("Array element is in descending order.");
for(i=0;i<10;i++)
{
printf("%dt",a[i]);
}
getch();
}
/*output*/
Enter the array elements:10 34 65 5 345 490 90 86 43 14
Array element is in descending order. 490 345 90 86 65
43 34 14 10 5
18. /*C-program to write array elements in ascending order.*/
#include<stdio.h>
#include<conio.h>
main()
{
int a[10],i,j,k;
clrscr();
printf("Enter the array elements:");
for(i=0;i<10;i++)
{
scanf("%dt",&a[i]);
}
for(i=0;i<9;i++) /*write array elements in ascending
order*/
{
for(j=i+1;j<10;j++)
{
if(a[i]>a[j])
{
k=a[i];
a[i]=a[j];
a[j]=k;
}
}
}
printf("Array element is in ascending order.");
for(i=0;i<10;i++)
{
printf("%dt",a[i]);
}
getch();
}
/*output*/
Enter the array elements:434 45 465 13 67 83 53 77 67 13
Array element is in ascending order. 13 13 45 53 67 67 77
83 434 465
19. /*c-program to check wether the entered no. is prime
or not*/
#include<stdio.h>
#include<conio.h>
main()
{
int n,i,r;
printf("Enter a number:");
scanf("%d",&n);
i=2;
while(i<=n-1)
{
r=n%i;
if(r==0)
break;
i++;
}
if(i==n)
printf("The entered number is a prime no.");
else
printf("The entered number is not a prime no.");
getch();
}
/*output*/
Enter a number:5
The entered number is a prime no.
Enter a number:10
The entered number is not a prime no.
Enter a number:173
The entered number is a prime no.
Enter a number:237
The entered number is not a prime no.