Program
Program
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c:
printf(“ enter the elements a and b”);
scanf(“%d%d”,&a,&b);
c=a+b;
printf(“sum of the elements is%d”,c);
getch();
}
Output:
#include< stdio.h>
#include< conio.h>
void main()
{
int i,j;
clrscr();
printf("Enter the i & j value=\n ");
scanf("%d%d",&i,&j);
printf(“before swap”);
Printf(“\n%d\n%d\n”,i,j);
printf(“after swap”);
i=i+j;
j=i-j;
i=i-j;
Printf(“\n%d\n%d\n”,i,j);
getch();
}
Output
Program
#include <stdio.h>
#include<conio.h>
void main()
{
float celc, faren;
clrscr();
printf("Enter temperature in celsius ");
scanf("%f",&celc);
faren= (1.8 * celc) +32;
printf("\n Temperature in Farenheit = %f", faren);
getch();
}
Output
Program:
#include <stdio.h>
#include <conio.h>
#include <math.h>
void main()
{
int a, b, c, d;
float r1, r2;
clrscr();
printf("Enter co-efficient for x^2 : ");
scanf("%d", &a);
printf("Enter co-efficient for x : ");
scanf("%d", &b);
printf("Enter const co-efficient : ");
scanf("%d", &c);
d = b*b - 4*a*c;
r1 = (-b + sqrt(d)) / (2.0 * a);
r2 = (-b - sqrt(d)) / (2.0 * a);
printf("Real roots are %.2f and %.2f", r1, r2);
getch();
}
Output:
Program:
#include <stdio.h>
#include <conio.h>
#define pi 3.14
main()
{
int radius;
float area, circum;
clrscr();
printf("Enter radius of the circle : ");
scanf("%d", &radius);
area = pi * radius * radius;
circum = 2 * pi * radius;
printf("Area is %.2f and circumference is %.2f",area,circum);
getch();
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int year;
clrscr();
printf("enter the year\n");
scanf("%d",&year);
if(year%4==0&&year%100!=0||year%400==0)
{
printf("it is leap year");
}
else
printf("it is not a leap year");
getch();
}
OUTPUT:
Program
#include<stdio.h>
void main()
{
int num;
printf("Enter the number...");
scanf("%d",&num);
if(num%2==0)
printf("The given number is a Even number");
else
printf("The given number is a Odd number");
}
Output
Program:
#include <stdio.h>
#include <conio.h>
void main()
{
int x,y,big;
clrscr();
printf("Enter the value of x,y : ");
scanf("%d%d", &x &y);
big=(x>y)?x:y;
printf("big is ….%d”,big);
getch();
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("enter the value of a and b\n");
scanf("%d%d",&a,&b);
if(a>b)
printf("%d is big",a);
else
printf("%d is big",b);
getch();
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter the value of a,b,c \n");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
{
printf("max=a");
}
else
{
printf("max=c");
}}
else if(b>c)
{
printf("max=b");
}
else
{
printf("max=c");
}
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,n;
clrscr();
printf("enter values for 'a'and 'b'\n");
scanf("%d%d",&a,&b);
printf("enter the choice \n");
scanf("%d",&n);
switch(n)
{
case 1:
c=a+b;
printf("the value of c is %d",c);
break;
case 2:
c=a-b;
printf("the value of c is %d",c);
break;
case 3:
c=a*b;
printf("the value of c is %d",c);
break;
case 4:
c=a/b;
printf("the value of c is %d",c);
break;
default:
printf("wrong choice !!");
}
getch();
}
OUTPUT:
Program
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,s=0;
clrscr();
printf("Enter no:");
scanf("%d",&n);
while(n>0)
{
r=n%10;
s=s+r;
n=n/10;
}
printf("\nSum of digits = %d",s);
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,n,sum=0,c;
clrscr();
printf("enter the number \n");
scanf("%d",&n);
a=n;
while(n>0)
{
c=n%10;
c=c*c*c;
sum=sum+c;
n=n/10;
}
if(sum==a)
printf("%d is armstrong number",sum);
else
printf("%d is not an armstrong number",sum);
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n,temp,a,rev=0;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
temp=n;
while(n>0)
{
a=n%10;
rev=rev*10;
rev=rev+a;
n=n/10;
}
if (temp==rev)
{
printf("it is palindrome");
}
else
{
printf("it is not palindrome");
}
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,flg=0;
clrscr();
printf("enter the number\n");
scanf("%d",&n);
for(i=2;i<=n;i++)
{
if (n%i==0)
{
flg=1;
break();
}
}
if (flg==0)
printf(“the given number is prime”);
else
printf(“the given number is not prime”);
getch();
}
Output:
Program
#include<stdio.h>
void main()
{
int n, first = 0, second = 1, next, c;
Output:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n, i, fact;
i=1;
fact=1;
scanf(“%d”, &n);
printf(“\n enter the number”);
while(i<=n)
{
fact=fact*i;
i=i+1;
}
printf(“Factorial of n is %d”, fact):
getch();
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b=0
clrscr();
for(a=0;a<100;a++)
if(a%2==0&&a%3!=0&&a%5!=0)
{
printf(“%d”,a);
b++;
}
printf(“no of counts %d”,b);
getch();
}
Output:
2 4 8 14 16 22 26 28 32 34 38 44
46 52 56 58 62 64 68 74 76 82 86 88
92 94 98
No of counts: 27
6(a) SORTING
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],n,i,j,temp;
clrscr();
printf("enter the limit \n");
scanf("%d",&n);
printf("enter the array element \n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n-1;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 element n is ");
for (i=0;i<n;i++)
{
printf("%d",a[i]);
}
getch();
}
OUTPUT:
Program:
#include <stdio.h>
#include<conio.h>
void main()
{
int array[100], search, c, n;
clrscr();
printf("Enter the number of elements in array\n");
scanf("%d",&n);
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int m,n,p,q,i,j;
clrscr();
printf("enter the row & column size of matrix a \n");
scanf("%d%d",&m,&n);
printf("enter the row & column size of matrix b\n");
scanf("%d%d",&p,&q);
if (m==p&&n==q)
{
printf("enter the elements of matrix a \n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}}
printf("enter the elements of matrix b \n");
for (i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf ("%d",&b[i][j]);
}}
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
}}
printf("the added matrix is");
for (i=0;i<m;i++)
{
printf("\n");
for (j=0;j<n;j++)
{
printf("%3d",c[i][j]);
}}}
else
printf("the row & column size is invalid");
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10];
int m,n,p,q,i,j,k;
clrscr();
printf("enter the row & column size of matrix a \n");
scanf("%d%d",&m,&n);
printf("enter the row & column size of matrix b \n");
scanf("%d%d",&p,&q);
if (n==p)
{
printf("enter the elements of matrix a \n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}}
printf("enter the elements of matrix b \n");
for (i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf ("%d",&b[i][j]);
}}
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
c[i][j]=0;
for (k=0;k<n;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}}}
printf("the multiplied matrix is");
for (i=0;i<m;i++)
{
printf("\n");
for (j=0;j<n;j++)
{
printf("%3d",c[i][j]);
}}}
else
{
printf("not possible to multiplication");
}
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],m,n,i,j;
clrscr();
printf("enter the row & column size of matrix a \n");
scanf("%d%d",&m,&n);
printf("enter the elements of matrix a \n");
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}}
for (i=0;i<m;i++)
{
for (j=0;j<n;j++)
{
b[i][j]=a[j][i];
}}
printf("the matrix b is");
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<n;j++)
{
printf("%3d",b[i][j]);
}
}
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[10],str2[10],str3[10];
int i,j;
clrscr();
printf("Enter the two string:");
scanf("%s%s",&str1,&str2);
for(i=0;str1[i]!='\0';i++)
{
str3[i]=str1[i];
}
for(j=0;str2[j]!='\0';j++)
{
str3[i]=str2[j];
i++;
}
str3[i]='\0';
printf("Concatenated Stringis.....%s\n",str3);
getch();
}
OUTPUT:
PROGRAM:
#include<stdio.h>
#include<conio.h>
void main()
{
char str1[40],str2[40];
int n;
clrscr();
printf("enter the string 1 \n");
gets (str1);
strcpy(str2,str1);
strrev(str1);
n=strcmp(str1,str2);
if(n==0)
{
printf("the given string is palindrome");
}
else
printf("the given string is not palindrome");
getch();
}
OUTPUT:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
void swap(int,int);
int a,b,r;
clrscr();
printf("enter value for a&b: ");
scanf("%d%d",&a,&b);
swap(a,b);
getch();
}
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("after swapping the value for a & b is : %d %d",a,b);
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
void swap(int *num1, int *num2);
void main()
{
int x, y;
printf("\nEnter First number : ");
scanf("%d", &x);
printf("\nEnter Second number : ");
scanf("%d", &y);
printf("\nBefore Swaping x = %d and y = %d", x, y);
swap(&x, &y);
printf("\nAfter Swaping x = %d and y = %d", x, y);
getch();
}
Output:
Program:
#include<stdio.h>
#include<conio.h>
int recursive(int);
void main ()
{
int a,fact;
clrscr();
printf("Enter the number:");
scanf("%u",&a);
fact=recursive(a);
printf("The factorial of%d is %d",a,fact);
getch();
}
int recursive(x)
int x;
{
int f;
if(x==0)
return(1);
else
f=x*recursive(x-1);
return(f);
}
OUTPUT:
Enter thenumber5
The factorial of 5 is 120
10(a) EMPLOYEMENT PAYROLL USING STRUCTURE
Program:
#include<stdio.h>
#include<conio.h>
struct employee
{
char name[15];
int empid;
float bsal;
float net;
float gross;
};
void main()
{
struct employee emp;
float hra,da,tax;
clrscr();
printf("\nEmployee Details");
printf("\nEnter the employee name");
scanf("%s",&emp.name);
printf("\nEnter the employee id");
scanf("%d",&emp.empid);
printf("\nEnter the basic salary");
scanf("%f",&emp.bsal);
hra=((10*emp.bsal)/100);
da=((35*emp.bsal)/100);
tax=((15*emp.bsal)/100);
emp.gross=emp.bsal+hra+da;
emp.net=emp.gross-tax;
printf("\nEmployee name:%s",emp.name);
printf("\nEmployee no:%d",emp.empid);
printf("\nEmployee Basic salary:%f",emp.bsal);
printf("\nHRA:%f",hra);
printf("\nDA:%f",da);
printf("\nTax:%f",tax);
printf("\nNetSalary%f",emp.net);
printf("\nGross salary:%f",emp.gross);
getch();
}
OUTPUT:
Employee Details:
Enter the employee name : Robin
Enter the employee Id : 100
Enter the basic salary : 30000
PROGRAM:
#include<stdio.h>
main()
{
union student
{
char name[20];
char regno[12];
int avg;
char grade;
} stud[25],*ptr;
int i,no;
printf(“Enter the number of the students...”);
scanf(“%d”,&no);
for(i=0;i<no;i++)
{
printf(“\n student[%d] information:\n”,i+1);
printf(“Enter the name”);
scanf(“%s”,stud[i].name);
printf(“\nEnter the roll no of the student”);
scanf(“%s”,stud[i].regno);
printf(“\nEnter the average value of the student”);
scanf(“%d”,&stud[i].avg);
}
pt=stud;
for(pt=stud;pt<stud+no;ptr++)
{
if(ptr->avg<30)
ptr->grade=’D’;
else if(ptr->avg<50)
ptr->grade=’C’;
else if(ptr->avg<70)
ptr->grade=’B’;
else
ptr->grade=’A’;
}
printf(“\n”);
printf(“NAME REGISTER-NO AVERAGE GRADE\n”);
for(ptr=stud;ptr<stud+no;pt++)
{
printf(“%-20s%-10s”,ptr->name,ptr->regno);
printf(“%10d \t %c\n”,ptr->avg,ptr->grade);
}
}
OUTPUT: