Monday, 2 October 2017
Program To Find The Values Of Logical Operators Expressions.
#include<stdio.h>
main()
{
int x=60, y=200, b=2, c=160;
int exp1, exp2, exp3, exp4, exp5, exp6;
clrscr();
exp1= x<y;
exp2= x+y<y;
exp3= x*b==120;
exp4= (x==60)&&(y>b);
exp5= (y!=60)||(c>x);
exp6= !(x>60);
printf("Value of first expression is : %d\n",exp1);
printf("Value of second expression is : %d\n",exp2);
printf("Valye of third expression is : %d\n",exp3);
printf("Value of forth expression is : %d\n",exp4);
printf("Value of fith expression is : %d\n",exp5);
printf("Value of sixth expression is : %d\n",exp6);
}
main()
{
int x=60, y=200, b=2, c=160;
int exp1, exp2, exp3, exp4, exp5, exp6;
clrscr();
exp1= x<y;
exp2= x+y<y;
exp3= x*b==120;
exp4= (x==60)&&(y>b);
exp5= (y!=60)||(c>x);
exp6= !(x>60);
printf("Value of first expression is : %d\n",exp1);
printf("Value of second expression is : %d\n",exp2);
printf("Valye of third expression is : %d\n",exp3);
printf("Value of forth expression is : %d\n",exp4);
printf("Value of fith expression is : %d\n",exp5);
printf("Value of sixth expression is : %d\n",exp6);
}
Friday, 29 September 2017
Thursday, 7 September 2017
Program To Search An Element From Array
#include<stdio.h>
main()
{
int i,n,e,a[30];
clrscr();
printf("\nEnter total number of elements : ");
scanf("%d",&n);
printf("Enter %d Integer Numbers\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element you want to search : ");
scanf("%d",&e);
i=0;
while(i<n&&e!=a[i])
{
i++;
}
printf("The Element of Array is located at : %d position",i+1);
return(0);
}
main()
{
int i,n,e,a[30];
clrscr();
printf("\nEnter total number of elements : ");
scanf("%d",&n);
printf("Enter %d Integer Numbers\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("Enter the element you want to search : ");
scanf("%d",&e);
i=0;
while(i<n&&e!=a[i])
{
i++;
}
printf("The Element of Array is located at : %d position",i+1);
return(0);
}
Program To Sort The Array Elements
#include<stdio.h>
main()
{
int n,i,j,temp,a[30];
clrscr();
printf("\nEnter The Total Number Of Elements You Want In Array :");
scanf("%d",&n);
printf("Enter %d Integer Numbers\n",n);
for(i=0;i<n;++i)
scanf("%d",&a[i]);
for(i=0;i<n;++i)
{
for(j=i+1;j<n;++j)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("The Sorted Array Elements Is\n");
for(i=0;i<n;++i)
printf("%d\n",a[i]);
}
main()
{
int n,i,j,temp,a[30];
clrscr();
printf("\nEnter The Total Number Of Elements You Want In Array :");
scanf("%d",&n);
printf("Enter %d Integer Numbers\n",n);
for(i=0;i<n;++i)
scanf("%d",&a[i]);
for(i=0;i<n;++i)
{
for(j=i+1;j<n;++j)
{
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("The Sorted Array Elements Is\n");
for(i=0;i<n;++i)
printf("%d\n",a[i]);
}
Program To Reverse Of An Array Elements
#include<stdio.h>
main()
{
int a[25],n,i,j,temp;
clrscr();
printf("\nEnter The Number Of Elements You Want In Array : ");
scanf("%d",&n);
printf("Enter The %d Integer Numbers\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
j=i-1;
i=0;
while(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
i++;
j--;
}
printf("The Elements Of Reversed Array Is :");
for(i=0;i<n;i++)
printf("%d\n" ,a[i]);
return(0);
}
main()
{
int a[25],n,i,j,temp;
clrscr();
printf("\nEnter The Number Of Elements You Want In Array : ");
scanf("%d",&n);
printf("Enter The %d Integer Numbers\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
j=i-1;
i=0;
while(i<j)
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
i++;
j--;
}
printf("The Elements Of Reversed Array Is :");
for(i=0;i<n;i++)
printf("%d\n" ,a[i]);
return(0);
}
Program To Find Smallest And Biggest Number In Array Of Integer Numbers
#include<stdio.h>
main()
{
int a[20],n,i,big,small;
clrscr();
printf("\nEnter Total Numbers You Want In Array : ");
scanf("%d",&n);
printf("\nEnter The %d Integer Numbers\n",n);
for(i=0;i<=n;i++)
scanf("%d",&a[i]);
big=a[0];
for(i=0;i<=n;i++)
if(a[i]>big)
big=a[i];
printf("\nThe Largest Number In Array Is : %d",big);
small=a[0];
for(i=0;i<=n;i++)
if(a[i]<small)
small=a[i];
printf("\nThe Smallest Number Is: %d",small);
return(0);
}
main()
{
int a[20],n,i,big,small;
clrscr();
printf("\nEnter Total Numbers You Want In Array : ");
scanf("%d",&n);
printf("\nEnter The %d Integer Numbers\n",n);
for(i=0;i<=n;i++)
scanf("%d",&a[i]);
big=a[0];
for(i=0;i<=n;i++)
if(a[i]>big)
big=a[i];
printf("\nThe Largest Number In Array Is : %d",big);
small=a[0];
for(i=0;i<=n;i++)
if(a[i]<small)
small=a[i];
printf("\nThe Smallest Number Is: %d",small);
return(0);
}
Tuesday, 5 September 2017
Program To Check Whether A Given String Is Palindrome Or Not.
#include<stdio.h>
#include<string.h>
main()
{
char strng[30];
int i,lngth,flag=0;
printf("Enter a string : ");
scanf("%s",&strng);
lngth=strlen(strng);
for(i=0;i<lngth;i++)
{
if(strng[i]!=strng[lngth-i-1])
{
flag=1;
break;
}
}
if(flag)
printf("%s is not a palindrome");
else
printf("%s is a palindrome");
returm 0;
}
#include<string.h>
main()
{
char strng[30];
int i,lngth,flag=0;
printf("Enter a string : ");
scanf("%s",&strng);
lngth=strlen(strng);
for(i=0;i<lngth;i++)
{
if(strng[i]!=strng[lngth-i-1])
{
flag=1;
break;
}
}
if(flag)
printf("%s is not a palindrome");
else
printf("%s is a palindrome");
returm 0;
}
Program To Check Whether A Given Number Is Palindrome Or Not.
#include<stdio.h>
main()
{
int num;
int temp;
int digit;
int rnum=0;
clrscr();
printf("Enter The Integer Number : ");
scanf("%d",&num);
temp=num;
do{
digit=temp%10;
temp=temp/10;
rnum=rnum*10+digit;
}
while(temp>0);
if(rnum==num)
printf("The Given Number Is Palindrome");
else
printf("The Given Number Is Not Palindrome");
}
main()
{
int num;
int temp;
int digit;
int rnum=0;
clrscr();
printf("Enter The Integer Number : ");
scanf("%d",&num);
temp=num;
do{
digit=temp%10;
temp=temp/10;
rnum=rnum*10+digit;
}
while(temp>0);
if(rnum==num)
printf("The Given Number Is Palindrome");
else
printf("The Given Number Is Not Palindrome");
}
Tuesday, 29 August 2017
Monday, 28 August 2017
Program To Check Whether A Number is Odd or Even.
#include<stdio.h>
void main()
{
int n;
clrscr();
printf("Enter the integer value\n");
scanf("%d",&n);
if(n%2==0)
printf("The value is even");
else
printf("The value is odd");
}
void main()
{
int n;
clrscr();
printf("Enter the integer value\n");
scanf("%d",&n);
if(n%2==0)
printf("The value is even");
else
printf("The value is odd");
}
Sunday, 27 August 2017
Program To Calculate Customers Telephone Bill
#include<stdio.h>
void main()
{
int units, custno;
float charge;
clrscr();
printf("Enter customer number and unit consumed\n");
scanf("%d%d",&custno,&units);
if(units<=200)
charge=0.5*units;
else if(units<=400)
charge=100+0.25*(units-200);
else if(units<=600)
charge=230+0.8*(units-400);
else
charge=390+(units-600);
printf("Customer no:%d consumed :%d units\n",custno,units);
printf("Total bill amount is : %.2f\n",charge);
}
void main()
{
int units, custno;
float charge;
clrscr();
printf("Enter customer number and unit consumed\n");
scanf("%d%d",&custno,&units);
if(units<=200)
charge=0.5*units;
else if(units<=400)
charge=100+0.25*(units-200);
else if(units<=600)
charge=230+0.8*(units-400);
else
charge=390+(units-600);
printf("Customer no:%d consumed :%d units\n",custno,units);
printf("Total bill amount is : %.2f\n",charge);
}
Sunday, 20 August 2017
Program to Perform all the Arithmetic Operations
#include<stdio.h>
main()
{
int first,second,Add,Sub,Mul;
float Div;
clrscr();
printf("Enter two integer numbers\n");
scanf("%d%d",&first,&second);
Add=first+second;
Sub=first-second;
Mul=first*second;
Div=first/second;
printf("Sum=%d\n",Add);
printf("Difference=%d\n",Sub);
printf("Multiplication=%d\n",Mul);
printf("Division=%f\n",Div);
return 0;
}
main()
{
int first,second,Add,Sub,Mul;
float Div;
clrscr();
printf("Enter two integer numbers\n");
scanf("%d%d",&first,&second);
Add=first+second;
Sub=first-second;
Mul=first*second;
Div=first/second;
printf("Sum=%d\n",Add);
printf("Difference=%d\n",Sub);
printf("Multiplication=%d\n",Mul);
printf("Division=%f\n",Div);
return 0;
}
Friday, 18 August 2017
Program to Calculate Simple Interest and Compound Interest
#include<stdio.h>
#include<math.h>
int main()
{
float p,q,r,smpi,cmpi;
int n;
clrscr();
printf("Enter the value of principle p = ");
scanf("%f",&p);
printf("Enter the value of rate r = ");
scanf("%f",&r);
printf("Enter the value of period in year n = ");
scanf("%d",&n);
smpi=((p*r*n)/100);
printf("The Simple Interest is=%f \n",smpi);
q=1+(r/100);
cmpi=p*pow(q,n)-p;
printf("The Compound Interest is=%f \n",cmpi);
return 0;
getch();
}
#include<math.h>
int main()
{
float p,q,r,smpi,cmpi;
int n;
clrscr();
printf("Enter the value of principle p = ");
scanf("%f",&p);
printf("Enter the value of rate r = ");
scanf("%f",&r);
printf("Enter the value of period in year n = ");
scanf("%d",&n);
smpi=((p*r*n)/100);
printf("The Simple Interest is=%f \n",smpi);
q=1+(r/100);
cmpi=p*pow(q,n)-p;
printf("The Compound Interest is=%f \n",cmpi);
return 0;
getch();
}
OUTPUT:-
Program To Perform Logical Operator
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("Enter the value of a,b and c\n");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(b>c))
printf("\na is greater than b =%d",a);
else
printf("\nb is greater than a =%d",b);
if(a>c)
printf("\na is greater value than c =%d",a);
else
printf("\nc is greater value than a =%d",c);
if((a==b)||(a==c))
printf("\na value is equal to b");
else
printf("\nvalues are not equal");
getch();
}
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("Enter the value of a,b and c\n");
scanf("%d%d%d",&a,&b,&c);
if((a>b)&&(b>c))
printf("\na is greater than b =%d",a);
else
printf("\nb is greater than a =%d",b);
if(a>c)
printf("\na is greater value than c =%d",a);
else
printf("\nc is greater value than a =%d",c);
if((a==b)||(a==c))
printf("\na value is equal to b");
else
printf("\nvalues are not equal");
getch();
}
Program To Perform Relational Operator
#include<stdio.h>
#include<conio.h>
main()
{
int x,y,z;
clrscr();
printf("Enter the values of x,y and z\n");
scanf("%d%d%d,",&x,&y,&z);
if(x==y)
printf("\nBoth the values are same =%d",x,y);
if(x>y)
printf("\nThe value of x is greater =%d",x);
else
printf("\nThe value of y is greater =%d",y);
if(y!=z)
printf("\nThe value of y is not equal to =%d",y);
getch();
}
#include<conio.h>
main()
{
int x,y,z;
clrscr();
printf("Enter the values of x,y and z\n");
scanf("%d%d%d,",&x,&y,&z);
if(x==y)
printf("\nBoth the values are same =%d",x,y);
if(x>y)
printf("\nThe value of x is greater =%d",x);
else
printf("\nThe value of y is greater =%d",y);
if(y!=z)
printf("\nThe value of y is not equal to =%d",y);
getch();
}
Friday, 4 August 2017
SWAPPING OF TWO VALUES WITHOUT USING THIRD VARIABLE
#include<stdio.h>
#include<conio.h>
main()
{
int a=8, b=12;
clrscr();
printf("Before swap of two numbers a=%d b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("After swap of numbers a=%d b=%d",a,b);
getch();
}
#include<conio.h>
main()
{
int a=8, b=12;
clrscr();
printf("Before swap of two numbers a=%d b=%d\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("After swap of numbers a=%d b=%d",a,b);
getch();
}
Thursday, 27 July 2017
PROGRAM TO FIND GEOMETRIC MEAN
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int a[10],n,i;
double sum=0, gm;
clrscr();
printf("Enter the total no. of elements");
scanf("%d",&n);
printf("Enter the elements\n");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
sum =sum+(log10(a[i]));
gm=exp(sum/n*log(10));
printf("Geometric mean is %f",gm);
getch();
}Sunday, 16 July 2017
PROGRAM TO FIND ARITHMETIC MEAN
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],n,i,s;
float mean;
clrscr();
printf("enter how many terms u want to enter\n");
scanf("%d",&n);
printf("enter %d terms\n",n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
s=0;
for(i=0;i<n;i++)
s+=a[i];
mean=s/n;
printf("mean is %f",mean);
getch();
}
Saturday, 8 July 2017
Program to read name of a employee, employee number and salary from the keyboard and writes same to binary file
#include<stdio.h>
struct
employee
{
int eno,salary;
char name[20];
}
main()
{
struct employee e;
char ans;
FILE *fp;
fp=fopen("file9.out","wb");
if(fp==NULL)
{
printf("Error in file
opening");
exit(0);
}
do
{
printf("\nEmployee
No.");
scanf("%d",&e.eno);
printf("\nName :");
scanf("%s",&e.name);
printf("\nSalary");
scanf("%d",&e.salary);
fwrite(&e,sizeof(e),1,fp);
printf("\nDo you want to
add more records y/n");
ans=getch();
}while(ans !='n');
fclose(fp);
}
Program to demonstrate pointer to structure
#include<stdio.h>
main()
{
struct
student
{
int
roll;
char
name[20];
int
age;
char
class[8];
};
struct
student s,*ptr;
ptr=&s;
printf("Enter
the student record\n");
printf("Roll
no. :");
scanf("%d",&ptr->roll);
printf("Name
:");
scanf("%s",&ptr->name);
printf("Age:");
scanf("%d",&ptr->age);
printf("Class
:");
scanf("%s",&ptr->class);
printf("\n
Record details are\n");
printf("Roll
no: %d\n",ptr->roll);
printf("Name:
%s\n",ptr->name);
printf("Age:
%d\n",ptr->age);
printf("Class
: %s\n",ptr->class);
}
Program to show nesting of macros
#include<stdio.h>
#define SQU(x)((x)*x)
#define CUBE(x)(SQU(x)*x)
int main()
{
int
x,y;
clrscr();
x=SQU(3);
y=CUBE(3);
printf("\nSquare
of 3 : %d",x);
printf("\nCube
of 3 : %d",y);
return(0);
}
Program to demonstrate pointer to function
#include<stdio.h>
main()
{
void
mess();
void
(*ptr)();
ptr=mess;
clrscr();
printf("Address
of the function is %d\n",ptr);
(*ptr)();
}
void
mess()
{
printf("I
am in the subprogram\n");
}
Program to demonstrate enumerated data types.
#include<stdio.h>
enum month
{Jan,Feb,Mar,Apr,May,June,July,Aug,Sep,Oct,Nov,Dec,Next};
main()
{
int
m;
float
pay,sum=0;
printf("\n");
for(m=Jan;m<=Dec;m++)
{
printf("Enter
the pay of month %d :",m+1);
scanf("%f",&pay);
sum+=pay;
}
printf("Total
Salary =%f",sum);
}
Program to demonstrate dynamic memory allocation
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
main()
{
char
*mem_allocation;
clrscr();
mem_allocation=
malloc( 20* sizeof(char));
if(mem_allocation==NULL)
{
printf("couldn't
able to allocate requested memory\n");
}
else
{
strcpy(mem_allocation,"Besties");
}
printf("Dynamically
allocated memory content:""%s",mem_allocation);
free(mem_allocation);
}
Program to demonstrate use of #define
#include<stdio.h>
#define NAME "vokytoky"
#define AGE 15
int main()
{
clrscr();
printf("%s
is over %d years old.\n",NAME,AGE);
return
0;
}
Program to demonstrate conditional compilation.
#include<stdio.h>
int main()
{
int
i=2;
clrscr();
#ifdef
DEF
{
i*=i;
}
#else
{
printf("The
answer is %d\n",i);
}
#endif
return
0;
}Program to demonstrate array of strings
#include<stdio.h>
#include<string.h>
void main()
{
char
name[35][21];
int
n,i;
clrscr();
printf("Enter
numbers of students");
scanf("%d",&n);
printf("Enter
the %d students name\n",n);
for(i=0;i<=n;++i)
{
gets(name[i]);
}
printf("\n List
of students is");
for(i=0;i<=n;++i)
puts(name[i]);
}Monday, 26 June 2017
Program to store record of 'n' employees/students
#include<stdio.h>
main()
{
struct
employee
{
char
name[20];
int
basic;
};
struct employee e[10];
int
n,i;
float
da[10],hra[10],total[10];
clrscr();
printf("Enter
the number of employees :");
scanf("%d",&n);
for(i=1;i<=n;++i)
{
printf("\nEnter
the data of employee %d\n",i);
printf("Name
:");
scanf("%s",&e[i].name);
printf("Basic
Pay :");
scanf("%d",&e[i].basic);
da[i]=e[i].basic
* 0.37;
hra[i]=e[i].basic
* 0.1;
total[i]=e[i].basic+da[i]+hra[i];
}
printf("Name Basic Pay DA HRA
TOTAL\n");
for(i=1;i<=n;++i)
{
printf("%s%6d%10.2f%10.2f%10.2f\n",e[i].name,e[i].basic,da[i],hra[i],total[i]);
}
}
Subscribe to:
Posts (Atom)
Write a program to draw a circle using mid-point circle drawing algorithm.
#include<iostream.h> #include<graphics.h> #include<conio.h> void drawcircle(int x0, int y0, int r) { ...
-
#include<iostream.h> #include<conio.h> #include<graphics.h> void drawCircle(int x, int y, int xc, int yc); void...
-
#include<stdio.h> #include<conio.h> main() { int a=8, b=12; clrscr(); printf("Before swap of two numbers a=%d b=%...
-
#include<stdio.h> main() { int num,i=1; printf("Enter the number whose multiple you want"); scanf("%d",...