You are on page 1of 69

INDEX

S NAME OF THE PROGRAMS REMARKS


NO.
1 Program to find the area of triangle.
2 Program to find the area of rectangle.

3 Program to calculate sum of three numbers.

4 Program to calculate marks of five subject and


print total marks & percentage of marks.

5 Program to calculate area of the circle.

6 Program to calculate the simple interest.

7 Program to check whether entered number is


odd or even.

8 Program to check whether the input year is a


leap year or not.

9 Program to read salary of an employee and


print grade.

10 Program to read 3 different numbers and find


largest amongst them.
11 Program to check whether the person is eligible
for vote or not.
12 Program to create a simple calculator.

13 Program to read marks of 5 subjects and print


total marks and percentage of students. Aslo
check if student scored a distinction.

14 Program to check a number if it is a positive,


negative number or zero.

15 Program to read a day of week in digit and print


appropriate message.
16 PROGRAM to create a calculator using switch
case.
17 Program to read a day of week in digit and print
appropriate message.

18 Program to create a calculator using switch


case.
19 Program to print star pyramid pattern.

20 Program program to calculate the sum of first n


even numbers.

21 Program to count the numbers between 1 to 50


and print the numbers which are not divisible by
2, 3 and 5.
22 Program read a number and find factorial.

23 Program to print the square roots from 1 to 9.

24 Program to check whether a given number is


palindrome or not.

25 Program to print sum of digits using recursion.

26 Program to calculate factorial of given number


by using recursion.

27 Program to print fibonacci series for n terms.

28 Program to calculate cube of a number with


separate function cube.

29 Program to read two integer numbers and find


their sum, difference, product and quotient using
separate function.

30 Program to convert decimal number to binary


number.

31 Program to read matrix of size 3*3 and display


transpose of matrix.
31 Program to calculate sum of all elements in
matrix.

32 Program to read an array of 7 integers and sort


it in descending order.

33 Program to read an array of 8 integer values


and find sum, average, greatest number and
lowest number.

34 Program to find the second maximum and


second minimum element from an array along
with their positions.

35 Program to read matrix of size 3*5 and count


zeros present in the matrix.

36 Program t0 program to accept 'n' numbers from


user, store these numbers into an array and
count the number of occurrences of each
number.
37 Program to program to accept 'n' numbers and
store all prime numbers in an array and display.
38 Program to read 3*3 matrix and check sum of
diagonal element is same or not.
39 Program to accept five integer elements in an
array and print odd numbers.
40 Program to program to accept a string from
user and reverse it.
41 Program to read a string and check if it is
palindrome.
42 Program to check whether the entered
character is digit or an alphabet.
43 Program to accept 'n' numbers from user and
sort them in ascending order using dynamic
memory allocation.
44 Program to display sum of all elements in matrix by
using dynamic memory allocation.
45 Program to program the values of two variables by
using call by reference.
46 Program to read information of student. It contains
name, roll number, birthday, admission date.
Calculate age of student at the time of admission.
47 Program to read the details of two workers and
calculate total payment of workers using structure.
48 Program to create student structure having field
roll_no, stud_name, class. Pass this entire structure
to function and display the structure elements.
1. PROGRAM TO FIND THE AREA OF TRIANGLE.

#include <stdio.h>
int main() {
int height,base;
float area;
printf("ENTER THE HEIGHT OF THE TRIANGLE : ");
scanf("%d",&height);
printf("ENTER THE BASE OF THE TRIANGLE : ");
scanf("%d",&base);
area = (height*base)/(float)2;
printf("THE AREA OF THE TRIANGLE IS : %.1f",area);

printf("\n\nPROGRAM MADE BY 6002 AKASH");


return 0;
}

OUTPUT
2. PROGRAM TO FIND THE AREA OF RECTANGLE.

#include <stdio.h>
int main() {
printf("AREA OF RECTANGLE\n");
int area,l,b;
printf("ENTER THE LENGTH OF RECTANGLE : ");
scanf("%d",&l);
printf("ENTER THE BREADTH OF RECTANGLE : ");
scanf("%d",&b);
area = l*b;
printf("AREA OF RECTANGLE : %d",area);
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
3. PROGRAM TO CALCULATE SUM OF THREE NUMBERS.

#include<stdio.h>
int main()
{
int num1,num2,num3,sum;
printf("ENTER FIRST NUMBER :");
scanf("%d", &num1);
printf("ENTER SECOND NUMBER :");
scanf("%d", &num2);
printf("ENTER THIRD NUMBER :");
scanf("%d", &num3);
sum=num1+num2+num3;
printf("SUM OF THE NUMBERS ARE : %d",sum);
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
4. PROGRAM TO CALCULATE MARKS OF FIVE SUBJECT AND PRINT TOTAL
MARKS & PERCENTAGE OF MARKS.

#include<stdio.h>
int main()
{
int num1,num2,num3,sum;
printf("ENTER FIRST NUMBER :");
scanf("%d", &num1);
printf("ENTER SECOND NUMBER :");
scanf("%d", &num2);
printf("ENTER THIRD NUMBER :");
scanf("%d", &num3);
sum=num1+num2+num3;
printf("SUM OF THE NUMBERS ARE : %d",sum);
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
5. PROGRAM TO CALCULATE AREA OF THE CIRCLE.

#include<stdio.h>
int main()
{
printf("AREA OF CIRCLE\n");
int r;
float area;
printf("ENTER RADIUS : ");
scanf("%d",&r);
area = 3.14*r*r;
printf("AREA OF CIRCLE = %.1f",area);
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
6. PROGRAM TO CALCULATE THE SIMPLE INTEREST.

#include <stdio.h>
int main()
{
printf("CALCULATE SIMPLE INTEREST\n\n");
int amount,years;
float rate,SI;
printf(" ENTER PRINCIPAL AMOUNT : ");
scanf("%d",&amount);
printf(" ENTER NUMBERS OF YEARS : ");
scanf("%d",&years);
printf(" ENTER RATE OF INTEREST : ");
scanf("%f",&rate);
SI= amount*years*rate/100.0;
printf("\nSIMPLE INTEREST = %.1f",SI);
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
7. PROGRAM TO CHECK WHETHER ENTERED NUMBER IS ODD OR EVEN.

#include <stdio.h>
int main()
{
int num;
printf("Enter a Number : ");
scanf("%d",&num);
if(num%2==0)
printf("\n%d is Even Number.",num);
else
printf("\n%d is Odd Number.",num);
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
8. PROGRAM TO CHECK WHETHER THE INPUT YEAR IS A LEAP YEAR OR
NOT.

#include <stdio.h>
int main()
{
int yr;
printf("Enter Any Year: ");
scanf("%d",&yr);
if(((yr%4==0)&&(yr%100!=0)) || (yr%400)==0)
printf("%d is a Leap Year",yr);
else
printf("\n%d is NOT a Leap Year.",yr);
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
9. PROGRAM TO READ SALARY OF AN EMPLOYEE AND PRINT GRADE.

#include <stdio.h>
int main()
{
int sal;
printf("Enter Salary of Employee : ");
scanf("%d",&sal);
if(sal>=30000)
{
printf("\nGrade of Employee : A "); }
else if(sal>=20000)
{
printf("\nGrade of Employee : B "); }
else if(sal>=10000)
{
printf("\nGrade of Employee : C "); }
else
{
printf("\nGrade of Employee : D "); }
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
10. PROGRAM TO READ 3 DIFFERENT NUMBERS AND FIND LARGEST
AMONGST THEM.

#include <stdio.h>
int main()
{
int n1, n2, n3, large;
printf("\nEnter Three Numbers\n");
printf("--------------------------------\n");
printf("Enter First Number : ");
scanf("%d", &n1);
printf("\nEnter Second Number : ");
scanf("%d",&n2);
printf("\nEnter Third Number : ");
scanf("%d",&n3);
printf("--------------------------------\n");
if((n1>n2) && (n1>n3))
{
large = n1; }
else if(n2>n3)
{
large = n2; }
else
{
large = n3; }
printf("Largest Number = %d", large);
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
11. PROGRAM TO CHECK WHETHER THE PERSON IS ELIGIBLE FOR
VOTE OR NOT.

#include <stdio.h>
int main()
{
int age;
printf("Enter your age:");
scanf("%d",&age);
if(age >=18)
{
printf("You are eligible for voting");
}
else
{
printf("You are not eligible for voting");
}
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT
12. PROGRAM TO CREATE A SIMPLE CALCULATOR.

#include <stdio.h>
int main() {
char operator;
double n1, n2;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%lf %lf",&n1, &n2);
switch(operator)
{
case '+':
printf("%.1lf + %.1lf = %.1lf",n1, n2, n1+n2);
break;

case '-':
printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
break;

case '*':
printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
break;

case '/':
printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
break;
default:
printf("Error! operator is not correct");
}
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}
OUTPUT
13. PROGRAM TO READ MARKS OF 5 SUBJECTS AND PRINT TOTAL MARKS AND
PERCENTAGE OF STUDENTS. ASLO CHECK IF STUDENT SCORED A DISTINCTION.

#include<stdio.h>
int main()
{
int m1,m2,m3,m4,m5,tot;
float per;
printf("Enter Marks of Five Subjects : \n");
scanf("%d %d %d %d %d", &m1,&m2,&m3,&m4,&m5);
tot=m1+m2+m3+m4+m5;
printf("\nTotal Marks of Student = %d\n",tot);
if(m1>=40 && m2>=40 && m3>=40 && m4>=40 && m5>=40)
{
printf("\nStudent is PASS\n");
per= tot/5.0;
printf("\nPercentage of a Student = %.2f\n",per);
if(per>=75) {
printf("\nStudent Got Distinction"); } }
else
{
printf("\nStudent is FAIL");

}
printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;
}

OUTPUT
14. PROGRAM TO CHECK A NUMBER IF IT IS A POSITIVE , NEGATIVE NUMBER OR ZERO.

#include <stdio.h>
int main()
{
int n;
printf("Enter Any Number : ");
scanf("%d", &n);
if(n > 0)
{
printf("\n%d is POSITIVE Number",n); }
else if(n < 0)

{
printf("\n%d is NEGATIVE Number",n);
}

else
{
printf("\nEntered number is ZERO");
}
printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;
}

OUTPUT
15. PROGRAM TO READ A DAY OF WEEK IN DIGIT AND PRINT
APPROPRIATE MESSAGE. 1: HOLIDAY
*/ 2, 3, 4, 5: WORKING DAY

6,7: HALF DAY */

#include<stdio.h>

int main(){

int n;

printf("Enter Day of Week in Digit : ");

scanf("%d",&n);

printf("-------------------------------\n\t");

switch(n) {

case 1:

printf("Holiday");

break;

case 2:

case 3:

case 4:

case 5:

printf("Working Day");

break;

case 6:

case 7:

printf("Half Day");

break;

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
16. PROGRAM TO CREATE A CALCULATOR USING SWITCH CASE.

#include<stdio.h>
#include<stdlib.h>
int main(){
int a,b,c,ch;
float d;
printf("=======================");
printf("\n\tMENU");
printf("\n=======================");
printf("\n 1] Addition");
printf("\n 2] Subtraction");
printf("\n 3] Multiplication");
printf("\n 4] Division");
printf("\n 5] Remainder");
printf("\n 6] Larger out of two");
printf("\n 0] Exit");
printf("\n=======================\n");
printf("Enter your choice : ");

scanf("%d",&ch);
printf("-----------------------\n");
if(ch<=6 && ch>0)
{
printf(" Enter Two Numbers\n");
printf("-----------------------\n");
printf("Enter First Number : ");
scanf("%d", &a);
printf("\nEnter Second Number : ");
scanf("%d",&b);
printf("-----------------------\n");
}
switch(ch){
case 1:
c=a+b;
printf("Addition of Numbers = %d",c);
break;
case 2:
c=a-b;
printf("Subtraction of Numbers = %d", c);
break;
case 3:
c=a*b;
printf("Multiplication of Numbers = %d",c);
break;
case 4:
d=a/(float)b;
printf("Division of Numbers = %.2f",d);
break;
case 5:
c=a%b;
printf("Remainder of Numbers = %d", c);
break;
case 6:
if(a>b)
printf("%d is Larger Than %d ",a,b);
else
if(b>a)
printf("%d is Larger Than %d",b,a);
else
printf("%d and %d are SAME", a,b);
break;
case 0:
printf("Terminated by Choice");
exit(0); // For this function include header file stdlib.h
break;
default:
printf("Invalid Choice");
}
printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;
}
OUTPUT

17. PROGRAM TO PRINT STAR PYRAMID PATTERN.

#include<stdio.h>
int main()
{
int i,a,b;
for(a=4, b=1; b<=4;a--,b++) {
for(i=1;i<a;i++)
printf(" ");
for(i=1;i<=b;i++)
printf("* ");
printf("\n");
}
printf("\n\nPROGRAM MADE BY 6002 AKASH");
return 0;
}

OUTPUT

18. PROGRAM TO CALCULATE THE SUM OF FIRST N EVEN NUMBERS .

#include<stdio.h>

int main(){

int i=1,n,s=0;

printf("Enter number to set range : ");

scanf("%d",&n);

printf("\nEven numbers in range 1 to %d :\n\n",n);

for(i=1;i<=n;i++)

if(i%2==0)

printf("%d ",i);

s=s+i;

} }
printf("\n\nSum of even numbers in range 1 to %d : %d",n,s);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
PROGRAM TO COUNT THE NUMBERS BETWEEN 1 TO 50 AND PRINT THE
19.
NUMBERS WHICH ARE NOT DIVISIBLE BY 2, 3 AND 5.
#include<stdio.h>

int main()

int i=1,c;

printf("The numbers from 1 to 50 which are not divisible\nby 2, 3 & 5


are:\n\n");

for(i=1;i<=50;i++)

if((i%2!=0)&&(i%3!=0)&&(i%5!=0))

printf("%d ",i);

c++;

} }

printf("\n\n Total Count = %d",c);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
20. PROGRAM READ A NUMBER AND FIND FACTORIAL.
#include<stdio.h>

int main()

int n, i;

long int fact=1;

printf("Enter Number : ");

scanf("%d",&n);

for(i=1;i<=n;i++)

fact=fact*i;

printf("\nFactorial of %d : %ld",n,fact);

return 0;

}
OUTPUT
21. PROGRAM to print the square roots from 1 to 9.
#include<stdio.h>

#include<math.h>

int main()

int i=1;

float square_roots;

printf("Square roots of numbers from 1 to 9 are:\n\n");

for(i=1;i<=9;i++)

square_roots=sqrt(i);

printf("\t%d = %.2f\n",i,square_roots);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT
22.PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS PALINDROME OR NOT.

#include<stdio.h>

int main()

int r=0,l,num;

long n;

printf("Enter Number : ");

scanf("%ld",&n);

num=n;

while(n>0)

l=n%10;

r=r*10+l;

n=n/10;

printf("\nReverse Number : %d",r);

if(r==num)

printf("\n\n%d is Palindrome Number.",num);

else

printf("\n\n%d is NOT Palindrome Number.",num);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
23. PROGRAM TO PRINT SUM OF DIGITS USING RECURSION.

#include<stdio.h>

int sod(int n)

if(n==0)

return 0;

else

return(n%10+sod(n/10));}

int main(){

int a,z;

printf("Enter Number : ");

scanf("%d",&a);

z=sod(a);

printf("\nSum of Digits : %d",z);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
24. PROGRAM TO CALCULATE FACTORIAL OF GIVEN NUMBER BY USING
RECURSION.

#include <stdio.h>

long fact(int n)

if(n==1)

return 1;

else

return(n*fact(n-1));

int main(){

long a,z;

printf("Enter Number : ");

scanf("%ld",&a);

z=fact(a);

printf("\nFactorial of %ld : %ld",a,z);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
25. PROGRAM to print Fibonacci series for n terms.

#include<stdio.h>

long int fib(long int i)

long int res;

if(i==0||i==1)

return (i);

else

res=fib(i-1)+fib(i-2);

return(res);

int main(){

long int res,n;

int i;

printf("/*How Many Terms You Want to \nCalculate in Fibonacci Series*/\n\nEnter


Limit : ");

scanf("%ld",&n);

printf("\n");

for(i=0;i<n;i++) {

res=fib(i);

printf("%ld ",res);}

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT

26. Calculate cube of a number with separate function cube.


#include<stdio.h>

float cube(long n)

long c;

c=n*n*n;

return c;

int main(){

long a,z;

printf("Enter Number : ");

scanf("%ld",&a);

z=cube(a);

printf("\nCube of %ld = %ld",a,z);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT

27. PROGRAM TO READ TWO INTEGER NUMBERS AND FIND THEIR SUM,
DIFFERENCE, PRODUCT AND QUOTIENT USING SEPARATE FUNCTION.

#include<stdio.h>

void sum(int x,int y){

int z;

z=x+y;

printf("Sum : %d\n",z);

void diff(int x,int y){

int z;

z=x-y;

printf("Difference : %d\n",z);

void mult(int x,int y){

int z;

z=x*y;

printf("Product : %d\n",z);

void div(int x,int y)

float z;
z=x/(float)y;

printf("Division : %.2f\n",z);

int main()

int a,b;

printf("Enter Two Numbers\n");

printf("---------------------------\n");

printf("Enter First Number : ");

scanf("%d", &a);

printf("\nEnter Second Number : ");

scanf("%d",&b);

printf("---------------------------\n");

sum(a,b);

diff(a,b);

mult(a,b);

div(a,b);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
28. PROGRAM to convert decimal number to binary number.

#include <stdio.h>

long DtoB(long n){

int r;

long binary = 0, i = 1;

while(n != 0)

r = n%2;

n = n/2;

binary= binary + (r*i);

i = i*10;

return binary;}

int main(){

long d,z;

printf("Enter Decimal Number : ");

scanf("%ld", &d);

z=DtoB(d);

printf("\nBinary Number of %ld : %ld", d,z);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT

29. PROGRAM TO READ MATRIX OF SIZE 3*3 AND DISPLAY TRANSPOSE OF MATRIX.
#include <stdio.h>

int main()

int a[4][4],t[4][4],i,j;

printf("Enter Elements for Matrix of Size 3*3:\n\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

scanf("%d",&a[i][j]);

printf("\n3*3 Matrix:\n\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

printf("%d ",a[i][j]);

printf("\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

{
t[j][i]=a[i][j]; // Transpose the matrix

/* Print the transpose matrix */

printf("\nTranspose of Matrix:\n\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++)

printf("%d ",t[i][j]);

printf("\n");

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
30. PROGRAM TO CALCULATE SUM OF ALL ELEMENTS IN MATRIX.
#include<stdio.h>

int main(){

int a[10][10],r,c,sum=0,i,j;

printf("/*How Many Rows You Want To \nEnter in Matrix*/\nEnter Limit : ");

scanf("%d",&r);

printf("\n/*How Many Columns You Want To \nEnter in Matrix*/\nEnter Limit : ");

scanf("%d",&c);

printf("\nEnter Elements for Matrix of Size %d*%d:\n\n",r,c);

for(i=0;i<r;i++)

for(j=0;j<c;j++)

scanf("%d",&a[i][j]);

printf("\n%d*%d Matrix : \n\n",r,c);

for(i=0;i<r;i++) {

for(j=0;j<c;j++)

printf("%2d ",a[i][j]); }

printf("\n");}

for(i=0;i<r;i++)

for(j=0;j<c;j++)

sum=sum+a[i][j];

printf("\nSum of All Elements in Matrix = %d",sum);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT
31. PROGRAM TO READ AN ARRAY OF 7 INTEGERS AND SORT IT IN DESCENDING ORDER.
#include <stdio.h>

int main()

int a[7],i,j,t;

printf("Enter 7 Numbers:\n");

for(i=0;i<7;i++)

scanf("%d",&a[i]);

for(i=0;i<6;i++)

for(j=i+1;j<7;j++)

if(a[i]<a[j])

t=a[i];

a[i]=a[j];

a[j]=t;

printf("\nNumbers in Descending Order:\n");

for(i=0;i<7;i++)

printf("%d ",a[i]);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
32. PROGRAMTO READ AN ARRAY OF 8 INTEGER VALUES AND FIND SUM,
AVERAGE, GREATEST NUMBER AND LOWEST NUMBER.
#include <stdio.h>

int main()

int a[8],i,s=0,g,l;

float avg;

printf("Enter 8 Numbers:\n");

for(i=0;i<8;i++)

scanf("%d",&a[i]);

s=s+a[i];

avg=s/8.0;

printf("Sum of Array Elements = %d\n",s);

printf("Average of Elements = %.2f\n",avg);

g=a[0];

for(i=0;i<8;i++)

if(a[i]>g)

g=a[i];

printf("Greatest Element = %d\n",g);

l=a[0];

for(i=0;i<8;i++)

if(a[i]<l)

l=a[i];

printf("Lowest Element = %d",l);

printf("\n\nPROGRAM MADE BY 6002 AKASH");


return 0;

OUTPUT

33. PROGRAMTO FIND THE SECOND MAXIMUM AND SECOND MINIMUM


ELEMENT FROM AN ARRAY ALONG WITH THEIR POSITIONS.
#include<conio.h>

#include<stdio.h>

#define max 100

void maxmin(int[],int);

void main()

int a[max],i,n;

printf("enter the limit of array: ");

scanf("%d",&n);

printf("enter the elements: ");


for(i=0;i<n;i++)

scanf("%d",&a[i]);

maxmin(a,n);

getch();

void maxmin(int a[max],int n)

int i,b[max],t,j;

for(i=0;i<n;i++)

b[i]=a[i]; }

for(i=0;i<n;i++)

for(j=0;j<n-1-i;j++) {

if(b[j]>b[j+1])

t=b[j];

b[j]=b[j+1];

b[j+1]=t;

}} }

for(j=0;j<n;j++)

if(a[j]==b[1])

{
printf("\nThe second minimum element is %d and its position is:
%d ",a[j],j);

if(a[j]==b[n-2])

printf("\nThe second maximum element is %d and its position is:


%d",a[j],j);

}}

printf("\n\nPROGRAM MADE BY 6002 AKASH");

OUTPUT
34. PROGRAM to read matrix of size 3*5 and count zeros present in the matrix.
#include <stdio.h>

int main()

int a[3][5],i,j,c=0;

printf("Enter Elements for Matrix of Size 3*5:\n\n");

for(j=0;j<=2;j++) // j is used for rows

for(i=0;i<=4;i++)

scanf("%d",&a[j][i]);}

printf("\nMatrix of Size 3*5: \n\n");

for(i=0;i<=2;i++)

for(j=0;j<=4;j++) {

printf("%3d ",a[i][j]); }

printf("\n"); }

for(j=0;j<=2;j++)

for(i=0;i<=4;i++)

if(a[j][i]==0)

c++;

printf("Zeros present in Above Matrix: %d",c);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT

35. PROGRAM T0 PROGRAM TO ACCEPT 'N' NUMBERS FROM USER, STORE THESE NUMBERS INTO
AN ARRAY AND COUNT THE NUMBER OF OCCURRENCES OF EACH NUMBER.

#include<stdio.h>

int main()

int n,i,j,c,a[20],t,num;

printf("/*How Many Numbers You Want\nTo Add in Array*/\n\nEnter Limit : ");

scanf("%d",&n);

printf("\nEnter %d Numbers:\n\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])

t=a[i];

a[i]=a[j];

a[j]=t;

} }}

/*for(i=0;i<n;i++)

printf("%d ",a[i]);

} */

printf("\n--------------------------------");

printf("\nNumber\t Frequency of Occurrence");

printf("\n--------------------------------\n");

for(i=0;i<n;i=j){

num=a[i];

c=1;

for(j=i+1;j<n;j++) {

if(a[j]!=num)

break;

else

c++; }

printf("\n%d\t\t%d",num,c);}

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT
36. PROGRAMTO ACCEPT 'N' NUMBERS AND STORE ALL PRIME NUMBERS IN
AN ARRAY AND DISPLAY.
#include<stdio.h>

int main()

int a[10],n,i,j,c=0,prime[10],t=0;

printf("/*How Many Numbers You Want\nTo Add in Array*/\n\nEnter Limit : ");

scanf("%d",&n);

printf("\nEnter %d Numbers in Array:\n\n",n);

for(i=0;i<n;i++)

scanf("%d",&a[i]);

for(i=0;i<n;i++) {

c=0;

for(j=2;j<a[i];j++)

if(a[i]%j==0)

c=1;

break;}}

if(c==0)

prime[t]=a[i];

t++; }}

printf("\nPrime Numbers in Above Array:\n\n");

for(i=0;i<t;i++)

printf(" %d ",prime[i]);
}

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;
}

OUTPUT

37. PROGRAM to read 3*3 matrix and check sum of diagonal element is same
or not.
#include <stdio.h>

int main()

int a[3][3],i,j,k,s1=0,s2=0;

printf("\nEnter Elements for Matrix of Size 3*3:\n\n");

for(i=0;i<=2;i++)

for(j=0;j<=2;j++) {

scanf("%d",&a[i][j]);}

printf("\n3*3 Matrix :\n\n");

for(i=0;i<=2;i++) {
for(j=0;j<=2;j++)

printf("%d ",a[i][j]); }

printf("\n");

printf("\nMajor Diagonal Elements : ");

for(k=0;k<=2;k++) {

printf("%d ",a[k][k]);

s1=s1+a[k][k];}

printf("\n\nMinor Diagonal Elements : ");

/* prints the minor diagonal elements */

for(i=0,j=2;i<=2&&j>=0;i++,j--)

printf("%d ",a[i][j]);

s2=s2+a[i][j]; }

printf("\n\nSum of Major Diagonal Elements : %d\n\n",s1);

printf("Sum of Minor Diagonal Elements : %d\n\n",s2);

if(s1==s2)

printf(" Sum is SAME");

else

printf(" Sum is NOT SAME");

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT

38. PROGRAM TO ACCEPT FIVE INTEGER ELEMENTS IN AN ARRAY AND PRINT ODD NUMBERS.

#include <stdio.h>

int main()

int a[5],i;

printf("Enter 5 Numbers:\n");

/*For accepting 5-integer numbers from user*/

for(i=0;i<5;i++)

scanf("%d",&a[i]);

printf("Odd Numbers in Array are:\n");


for(i=0;i<5;i++)

if(a[i]%2!=0) //Check number is odd

printf("%d ",a[i]);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT

39. PROGRAM TO ACCEPT A STRING FROM USER AND REVERSE IT.

#include<stdio.h>

#include<string.h>

int main()

{ char s[120], t;

int i=0, j = 0;

printf("Enter String : ");

gets(s);

j = strlen(s) - 1;

while (i < j){

t = s[i];

s[i] = s[j];
s[j] = t;

i++;

j--; }

printf("\nReverse String = %s", s);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return (0);

OUTPUT
40. PROGRAM TO READ A STRING AND CHECK IF IT IS PALINDROME.

#include<stdio.h>

#include<string.h>

int main(){

char s[120], t , s1[120];

int i=0, j = 0;

printf("Enter String : ");

gets(s);

strcpy(s1,s);

j = strlen(s) - 1;

while (i < j){

t = s[i];

s[i] = s[j];

s[j] = t;

i++;

j--;

printf("\nReverse String = %s", s);

if(strcmp(s,s1)==0)

printf("\n\n%s is Palindrome",s1);

else

printf("\n\n%s is Not Palindrome",s1);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return (0);

}
OUTPUT

41. PROGRAM TO CHECK WHETHER THE ENTERED CHARACTER IS DIGIT OR AN ALPHABET.

#include <stdio.h>

int main(){

char ch;

printf("Enter any character: ");

scanf("%c", &ch);

/* Checks if it is an alphabet */

if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))

printf("%c is ALPHABET.\n", ch);

if(ch >= '0' && ch <= '9')

printf("%c is DIGIT.\n", ch);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT

42. PROGRAM TO ACCEPT 'N' NUMBERS FROM USER AND SORT THEM IN ASCENDING ORDER
USING DYNAMIC MEMORY ALLOCATION.

#include<stdio.h>

#include<stdlib.h>

int main()

int *a,n,i,j,t;

printf("How many numbers you want to be sorted: ");

scanf("%d",&n);

a=(int *)malloc(n *sizeof(int));

printf("\nEnter %d Numbers: \n\n",n);

for(i=0;i<=n-1;i++)

scanf("%d", (a+i));

for(i=0;i<n;i++)

for(j=0;j<=i;j++)

if(*(a+i)<*(a+j))

t=*(a+i);

*(a+i)=*(a+j);
*(a+j)=t;

printf("\nAfter Sorting in Ascending Order: \n");

for(i=0;i<n;i++)

printf("\n%d",*(a+i));

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
43. PROGRAM TO DISPLAY SUM OF ALL ELEMENTS IN MATRIX BY USING DYNAMIC MEMORY
ALLOCATION.

#include<stdio.h>

#include<stdlib.h>

int main(){

int **a, row,col,i,j,s=0;

printf("Enter Limit for Rows : ");

scanf("%d",&row);

printf("\nEnter Limit for Columns : ");

scanf("%d",&col);

a=(int **)malloc(row*sizeof(int*));

for(i=0;i<row;i++){

a[i]=(int *)malloc(col*sizeof(int));}

printf("\nEnter Elements for Matrix of Size %d*%d:\n\n",row,col);

for(i=0;i<row;i++){

for(j=0;j<col;j++) {

scanf("%d",&a[i][j]); }}

printf("\n%d*%d Matrix : \n\n",row,col);

for(i=0;i<row;i++){

for(j=0;j<col;j++) {

printf("%3d ",a[i][j]);

printf("\n");

for(i=0;i<row;i++)

for(j=0;j<col;j++)
{

s=s+a[i][j];

printf("\nSum of All Elements in Matrix = %d",s);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT
44. PROGRAM TO SWAP THE VALUES OF TWO VARIABLES BY USING CALL BY REFERENCE.

#include<stdio.h>
void swap(int*n1,int*n2)
{
int temp;
temp=*n1;
*n1=*n2;
*n2=temp;
}
int main()
{
int a,b;
printf("Enter Two Numbers: \n");
scanf("%d%d",&a,&b);
printf("\nNumbers Before Swapping: \n");
printf("\n a=%d b=%d\n",a,b);
swap(&a,&b);
printf("\nNumbers After Swapping: \n");
printf("\n a=%d b=%d",a,b);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;
}
OUTPUT
45. PROGRAM TO READ INFORMATION OF STUDENT. IT CONTAINS NAME, ROLL NUMBER,
BIRTHDAY, ADMISSION DATE. CALCULATE AGE OF STUDENT AT THE TIME OF ADMISSION.

#include<stdio.h>

struct student{

int roll_num;

char name[20];

struct Date

int D;

int M;

int Y;

}bd,ad;

};

int main()

int r;

struct student a;

printf("\tEnter Student Details\n");

printf("----------------------------------------------------\n");

printf("Enter Roll-Number : ");

scanf("%d",&a.roll_num);

printf("Enter Name : ");

scanf("%s",a.name);

printf("Enter Birth-Date : ");

scanf("%d-%d-%d",&a.bd.D,&a.bd.M,&a.bd.Y);

printf("Enter Admission-Date : ");

scanf("%d-%d-%d",&a.ad.D,&a.ad.M,&a.ad.Y);
r=a.ad.Y-a.bd.Y;

printf("----------------------------------------------------\n");

printf("\nApproximate Age of Student at the Time of Admission\n");

printf("----------------------------------------------------\n");

printf("\t%d Years",r);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT


46. PROGRAM TO READ THE DETAILS OF TWO WORKERS AND CALCULATE TOTAL PAYMENT OF
WORKERS USING STRUCTURE.

#include<stdio.h>

struct worker{

char name[20];

int wage;

int wdays;};

int main(){

struct worker a,b;

printf("Enter Details of First Worker\n");

printf("-------------------------------\n");

printf("Enter Worker Name : ");

scanf("%s",a.name);

printf("Enter Wage : ");

scanf("%d",&a.wage);

printf("Enter wdays : ");

scanf("%d",&a.wdays);

printf("-------------------------------\n");

printf("Enter Details of Second Worker\n");

printf("-------------------------------\n");

printf("Enter Worker Name : ");

scanf("%s",b.name);

printf("Enter Wage : ");

scanf("%d",&b.wage);

printf("Enter wdays : ");

scanf("%d",&b.wdays);

printf("-------------------------------\n");

int p1=a.wage*a.wdays;
printf("Name of First Worker : %s\nPayment of First Worker : %d\n",a.name,p1);

printf("-------------------------------\n");

int p2=b.wage*b.wdays;

printf("Name of Second Worker : %s\nPayment of Second Worker : %d\n",b.name,p2);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;

}
OUTPUT
47. PROGRAM TO CREATE STUDENT STRUCTURE HAVING FIELD ROLL_NO,
STUD_NAME, CLASS. PASS THIS ENTIRE STRUCTURE TO FUNCTION AND
DISPLAY THE STRUCTURE ELEMENTS.

#include<stdio.h>

struct stud{

int roll_no;

char stud_name[20];

int std;

}s;

void student(struct stud s){

printf("Student details:\n");

printf("--------------------------\n");

printf("Roll Number : %d",s.roll_no);

printf("\nName : %s",s.stud_name);

printf("\nStd : %d",s.std);

int main()

printf("Enter Student Details\n");

printf("--------------------------\n");

printf("Roll Number : ");

scanf("%d",&s.roll_no);

printf("Name : ");

scanf("%s",s.stud_name);

printf("Std. : ");

scanf("%d",&s.std);

printf("--------------------------\n");
student(s);

printf("\n\nPROGRAM MADE BY 6002 AKASH");

return 0;
}
OUTPUT

48. PROGRAM TO CREATE A STRUCTURE OF STUDENT HAVING FIELDS


ROLL_NO, STUD_NAME, MARK1, MARK2, MARK3. CALCULATE TOTAL MARKS
AND AVERAGE MARKS. ARRANGE THE RECORDS IN DESCENDING ORDER OF
MARKS
#include<stdio.h>

struct student

int rno;

char name[20];

int marks[3];

int total;

float avg;

}stud[2];

int main()

{
int i,j;

struct student s;

for(i=0;i<2;i++)

printf("Enter Record for Student-%d \n",i+1);

printf("-----------------------------------\n");

printf("Enter Roll-No. : ");

scanf("%d",&stud[i].rno);

printf("Enter Name : ");

scanf("%s",stud[i].name);

stud[i].total=0;

for(j=0;j<3;j++)

printf("Enter Marks of Subject %d : ",j+1);

scanf("%d",&stud[i].marks[j]);

stud[i].total=stud[i].total+stud[i].marks[j] ;

stud[i].avg=stud[i].total/3.0;

printf("\n-----------------------------------\n");

for(i=0;i<2;i++)

for(j=i+1;j<2;j++)

if(stud[i].total<stud[j].total)

s=stud[i];

stud[i]=stud[j];
stud[j]=s;

printf("Records in Descending Order.\n (According to Total-Marks)");

printf("\n-----------------------------------\n");

printf("\n ROLLNO NAME TOTAL-MARKS AVG\n");

for(i=0;i<2;i++)

printf("\n %d\t %s\t %d\t


%.2f",stud[i].rno,stud[i].name,stud[i].total,stud[i].avg);

printf("\nPROGRAM MADE BY 6002 AKASH");

return 0;

OUTPUT

You might also like