You are on page 1of 22

1.

DEVELOP A C PROGRAM TO CONVERT FAHRENHEIT DEGREE CELSIUS :


PROGRAM:-
#include<stdio.h>
int main ()
{
float f, c;
printf("enter the fahrenheit value\n");
scanf("%f", &f);
c=(f-32)*(5.0/9.0);
printf ("%0.3f fahrenheit %0.3f celcius", f, c);
return 0;
}
OUTPUT:
2. DEVELOP A C PROGRAM TO FIND THE AREA OF A TRIANGLE USING FUNCTIONS

PROGRAM:-
#include <stdio.h>
#include <math.h>
float area1(float a, float b, float c);
int main()
{
float a, b, c, area;
printf("Enter the sides of the triangle\n");
scanf("%f%f%f", &a, &b, &c);
area = area1(a, b, c);
printf("area of the triangle is %.2f\n", area);
return 0;
}
float area1(float a, float b, float c)
{
float s, area;
s = (a+b+c)/2;
area = sqrt(s*(s-a)*(s-b)*(s-c));
return area;
}
OUTPUT:
3.DEVELOP A C PROGRAM TO FIND ALL POSSIBLE ROOTS OF A QUADRATIC
EQUATIONS

PROGRAM:-

#include<stdio.h>
#include<math.h>
int main()
{
int a,b,c;
float d,r1,r2;
printf("Enter a b c\n");
scanf("%d%d%d",&a,&b,&c);
d=b*b-4*a*c;
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
if(d>0)
{
printf("Roots are real and distinct\n");
printf("Roots1=%f \n Roots2=%f",r1,r2);
}
else if(d==0)
{
printf("Roots are Real and Equal\n");
printf("Roots1=%f\n Roots2=%f",r1,r2);
}
else
{
printf("Imaginary roots");
}
}

OUTPUT:-
4.DEVELOP A C PROGRAM TO DETERMINE WHETHER THE ENTERED CHARACTER IS
VOWEL OR CONSONANT USING SWITCH CASE STATEMENT

PROGRAM:-
#include <stdio.h>
int main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
switch(ch)
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
printf("Vowel");
break;
default: printf("Consonant");
}
return 0;
}

OUTPUT:-
5.DEVELOP A C PROGRAM TO PRINT EVEN NUMBERS FROM M TO N
PROGRAM:
#include <stdio.h>
int main()
{
int m,n,i;
printf("Enter the VALUE of m\n");
scanf("%d",&m);
printf("Enter the VALUE of n\n");
scanf("%d",&n);
for(i=m;i<=n;i++)
{
if(i%2==0)
printf("Entered number %d is even\n",i);
}
return 0;
}
OUTPUT:
6.DEVELOP A PROGRAM TO CALCULATE THE SUM OF SQUARE OF FIRST N ODD
NUMBERS
PROGRAMS:-
#include <stdio.h>
int main()
{ int sum=0,n,i;
printf("Enter the value of n\n");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
if(i%2!=0)
sum=sum + (i*i);
printf("The sum of the squares of the first n odd numbers is %d \n",sum);
}
return 0;
}
OUTPUT:

7. DEVELOP A PROGRAM TO PERFORM ADDITION OF TWO MATRICES


PROGRAM:-
#include <stdio.h>
int main() {
int r, c, a[100][100], b[100][100], sum[100][100], i, j;
printf("Enter the number of rows (between 1 and 100): ");
scanf("%d", &r);
printf("Enter the number of columns (between 1 and 100): ");
scanf("%d", &c);
printf("\nEnter elements of 1st matrix:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &a[i][j]);
}
printf("Enter elements of 2nd matrix:\n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("Enter element a%d%d: ", i + 1, j + 1);
scanf("%d", &b[i][j]);
}for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
sum[i][j] = a[i][j] + b[i][j];
}
printf("\nSum of two matrices: \n");
for (i = 0; i < r; ++i)
for (j = 0; j < c; ++j)
{
printf("%d ", sum[i][j]);
if (j == c - 1)
{
printf("\n\n");
}
}
return 0;
}

OUTPUT:
8.DEVELOP A C PROGRAM TO COPY ONE STRING INTO ANOTHER AND FIND ITS
LENGTH WITHOUT USING BUILT-IN FUNCTIONS
PROGRAMS:-
#include<stdio.h>
int main() {
char s1[100], s2[100];
int i,len=0;
printf("\nEnter the string :");
scanf("%s",s1);
i = 0;
while (s1[i] != '\0') {
s2[i] = s1[i];
i++;
len++;
}
s2[i] = '\0';
printf("\nCopied String is %s ", s2);
printf("Length of the new string is %d",len);
return 0;
}
OUTPUT:-
9.DEVELOP A C PROGRAM TO CREATE STUDENT STRUCTURE ,READ TWO
STUDENT DETAILS(STUDENT ROLL
NUMBER,NAME,SECTION,DEPARTMENT,FEES,AND RESULT I.E. , TOTAL
MARKS OBTAINED) AND PRINT THE STUDENTS DETAILS WHOHAS SCORED
THE HIGHEST.
PROGRAM:-

#include<stdio.h>
int main()
{
struct student
{
int srn;
char name[30];
char section[5];
char department[30];
float fees;
float result;
}
stud1,stud2;
printf("Enter roll number of the first student: \n");
scanf("%d",&stud1.srn);
printf("Enter name of the student :\n");
scanf("%s",stud1.name);
printf("Enter student section: \n");
scanf("%s",stud1.section);
printf("Enter student department: \n");
scanf("%s",stud1.department);
printf("Enter student fees:\n");
scanf("%f",&stud1.fees);
printf("Enter student final marks:\n");
scanf("%f",&stud1.result);
printf("Enter roll number of the second student: \n");
scanf("%d",&stud2.srn);
printf("Enter name of the student :\n");

scanf("%s",stud2.name);
printf("Enter student section: \n");
scanf("%s",stud2.section);
printf("Enter student department : \n");
scanf("%s",stud2.department);
printf("Enter student fees: \n");
scanf("%f",&stud2.fees);
printf("Enter student final marks:\n");
scanf("%f",&stud2.result);

if(stud1.result>stud2.result)
{
printf("Student details who scored the highest marks\n Roll number:%d\n Name:
%s\n Section:
%s\nDepartment:%s\nFees:%f\nResults:%f",stud1.srn,stud1.name,stud1.section,s
tud1.department,stud1.fees,stud1.result);
}
else
{
printf("Student details who scored the highest marks\n Roll number:%d\n Name:
%s\n Section:
%s\nDepartment:%s\nFees:%f\nResults:%f",stud2.srn,stud2.name,stud2.section,stu
d2.department,stud2.fees,stud2.result);
}
return 0;
}
OUTPUT:-
10.DEVELOP A C PROGRAM TO PERFORM ARITHMETIC
OPERATIONS(ADDITION,SUBTRACTION,MULTIPLICATION,DIVISION AND REMAINDER)
ON TWO INTEGERS USING INTEGERS.
PROGRAM:-
#include<stdio.h>
void add(int *a,int *b,int *s);
void sub(int *a,int *b,int *d);
void prod(int *a,int *b,int *m);
void quo(int *a,int *b,float *q);
void rem(int *a,int *b,int *r);
int main()
{
int num1,num2,sum,diff,mul,re;
float di;
printf("Enter any two numbers \n");
scanf("%d %d",&num1 ,&num2);
add(&num1,&num2,&sum);
printf("\nSum of 2 numbers = %d\n",sum);
sub(&num1,&num2,&diff);
printf("Difference of 2 numbers = %d\n",diff);
prod(&num1,&num2,&mul);
printf("Product of 2 numbers = %d\n",mul);
quo(&num1,&num2,&di);
printf("Division=%0.2f\n",di);
rem(&num1,&num2,&re);
printf ("Remainder =%d\n",re);
return 0;
}
void add(int *a,int *b,int *s)
{
*s= *a + *b;
}
void sub(int *a,int *b,int *d)
{
*d=*a - *b;
}
void prod(int *a,int *b,int *m)
{
*m= *a * *b;
}
void quo(int *a,int *b,float *q)
{
*q = (float)(*a / *b);
}
void rem(int *a,int *b,int *r)
{
*r= *a % *b;
}
OUTPUT:-
KUSHAL
PN SECTION
PN BATCH 2
ROLL NO : 21

You might also like