0% found this document useful (0 votes)
74 views

Fundamental Computer & Programing in C: Program File OF

The document provides an index and 11 programs written in C programming language to solve various problems involving arrays, strings, matrices, files, and other basic concepts. The programs cover tasks like finding the largest of given numbers, calculating averages, determining roots of quadratic equations, reversing strings, concatenating strings, representing a deck of cards, and checking for palindromes. The last program demonstrates reading and printing the contents of a file.

Uploaded by

Ranjeet Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Fundamental Computer & Programing in C: Program File OF

The document provides an index and 11 programs written in C programming language to solve various problems involving arrays, strings, matrices, files, and other basic concepts. The programs cover tasks like finding the largest of given numbers, calculating averages, determining roots of quadratic equations, reversing strings, concatenating strings, representing a deck of cards, and checking for palindromes. The last program demonstrates reading and printing the contents of a file.

Uploaded by

Ranjeet Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

PROGRAM FILE

OF
FUNDAMENTAL COMPUTER
&
PROGRAMING IN C

CBS Group Of Institution

Submitted To: Submitted By:

Mr. Ranjeet Singh(CSE) Name:

(Assistant Professor) Branch:

Roll No.
INDEX
S.No. Program Name Date Remark Sign
Write a program largest out of 3 number
1. entered by student using if else statement

Write a program largest out of 10 number


2. entered by student

Write a program to find average of male and


3. female height in a class .

Write a program to find roots of quadratic


4. equation

Write a program using array to find largest &


5. second largest out of 50 numbers

Write a program to multiply two matrices


6.
Write a program to read a string & write it in
7. revese order

Write a program to concatenate two strings of


8. different lengths

Represent a deck of playing cards using


9. arrays

Write a program to check that the input string


10. is a palindrome or not.

C Program To Read The File And Print The


11. Result On The Screen
PROGRAM 1
1) Write a program largest out of 3 number entered by student
using if else statement .
#include<conio.h>

#include<stdio.h>

void main()

clrscr();

int t,i,h;

printf("\n\n Enter the value of 't' =" );

scanf("%d",&t);

printf("\n\n Enter the value of 'i' =" );

scanf("%d",&i);

printf("\n\n Enter the value of 'h' =" );

scanf("%d",&h);

if (h>t&&h>i)

printf("\n\n the greatest number is = %d",h);

else

if(i>h&&i>t)

{
printf("\n\n the greatest number is 'i'= %d",i);

else

printf("\n\n the greatest number is 't' = %d",t);

getch();

OUTPUT :
PROGRAM 2
2) Write a program largest out of 10 number entered by student .
#include<conio.h>

#include<stdio.h>

void main()

clrscr();

int t,i,h=0;

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

printf("\n\n Enter the value of 't' number =" );

scanf("%d",&t);

if (h>t)

h;

else

h=t;

printf("\n\n the greatest number is = %d",h);


getch();

OUTPUT :
PROGRAM 3
3) Write a program to find average of male and female height in a
class .
#include<conio.h>

#include<stdio.h>

void main()

clrscr();

int t,i,h,sum1=0,sum2=0,f=0,m=0;

float avg1,avg2;

printf("\n Enter the total number of a students =");

scanf("%d",&t);

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

printf("\n Enter the height of a students =");

scanf("%d",&h);

if (h<6)

printf("\nthe height of a girls =%d",h);

sum2 +=h;

++f;

else
{

printf("\n the height of a boys =%d",h);

sum1 +=h;

++m;

avg1=sum1/m;

avg2=sum2/f;

printf("\n the average of boys(male) height is =


%f",avg1);
printf("\n the average of girls(female) height is =
%f",avg2) ;

getch();

OUTPUT :
PROGRAM 4
4) Write a program to find roots of quadratic equation.
#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

clrscr();

int a,c,b,D,x;

float x1,x2;

printf("\nenter the value of 'a'=") ;

scanf("%d",&a);

printf("\nenter the value of 'b'=") ;

scanf("%d",&b);

printf("\nenter the value of 'c'=") ;

scanf("%d",&c);

D = b*b - 4*a*c;

printf("\n\nthe value of D is= %d",D);

printf("\n\n\n enter 1 : for if D > 0\n\n\nenter key 2


: if D == 0\n\n\n enter key 3 : if D < 0\n\n\n\n where
x1 & x2 are roots ") ;

printf ("\n\n\nenter your choice from 1-3 = ");

scanf("%d",&x);
switch (x)

case 1:

printf ("\n\n\n\n roots are real");

x1 = - b + sqrt(D)/2*a;

x2 = - b - sqrt(D)/2*a;

printf ("\n\n\n\nthe value of root x1 = %f",x1);

printf ("\n\n\n\nthe value of root x2 = %f",x2);

break;

case 2:

x1 = - b + sqrt(D)/2*a;

x2 = - b - sqrt(D)/2*a;

printf ("\n\n\n\nthe value of root x1 = %f",x1);

printf ("\n\n\n\nthe value of root x2 = %f",x2);

break;

case 3:

x1 = - b + sqrt(D)/2*a;

x2 = - b - sqrt(D)/2*a;

printf ("\n\n\nroots are imaginary");

printf ("\n\n\n\nthe value of root x1 = %f",x1);

printf ("\n\n\n\nthe value of root x2 = %f",x2);

break;
default :

printf("you enter the the wrong number");

getch();

OUTPUT :
PROGRAM 5

5) Write a program using array to find largest & second largest out
of 50 numbers.
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int i,a[51],t;
printf("\n" );
a[50]=0;
for(i=0;i<50;i++)
{
printf("Enter the value of 't' number =" );
scanf("%d",&a[i]);
if (a[50]>a[i])
{
a[50];
}
else
{
a[50]=a[i];
t=a[i];
}
}
printf(" the first greatest number is = %d",a[50]);
a[51]=0;
for(i=0;i<50;i++)
{
if(t==a[i])
a[i]=0;
}
for(i=0;i<50;i++)
{
if(a[51]>a[i])
a[51];
else
a[51]=a[i];
}
printf("\n the second greatest number is = %d",a[51]);

getch();
}

OUTPUT :
PROGRAM 6

6) Write a program to multiply two matrices.


#include<conio.h>
#include<PROCESS.H>
#include<stdio.h>
void main()
{
clrscr();
int a[10][10],b[10][10],c[10][10],i,j,m,n,p,q,k;
printf("\n\ninput row & columns of a matrix:\n");
scanf("%d%d",&m,&n);
printf("\ninput row & columns of b matrix:\n");
scanf("%d%d",&p,&q);
if(n==p)

{
printf("\nmatrices can be multiplied");
}
else
{
printf("\nmatrices can not be multiplied");
exit(0);
}
printf("\n input matrix-a:\n");
for(i=0;i<m;++i)
{
for(j=0;j<n;++j)
scanf("%d",&a[i][j]);
}
printf("\n input matrix-b:\n");
for(i=0;i<p;++i)
{
for(j=0;j<q;++j)
scanf("%d",&b[i][j]);
}
printf("\n MATRIX-a:");
for(i=0;i<m;++i)
{
printf("\n");
for(j=0;j<n;++j)
{ printf("%d",a[i][j]);
printf(" "); }
}
printf("\n MATRIX-b:");
for(i=0;i<p;i++)
{
printf("\n");
for(j=0;j<q;j++)
{
printf("%d",b[i][j]);
printf(" ");
}
}
for(i=0;i<m;++i)
{ for(j=0;j<q;++j)
{
c[i][j]=0;
for(k=0;k<n;++k)
c[i][j]+=(a[i][k]*b[k][j]);
} }
printf("\n product of a & b matrices:");
for(i=0;i<m;++i)
{
printf("\n");
for(j=0;j<q;++j)
{ printf("%d",c[i][j]);
printf(" "); }
}
getch();
}
OUTPUT :
PROGRAM 7

7) Write a program to read a string & write it in revese order.

#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
void main()
{
clrscr();
int len;
char s[30];
printf("\n\n Enter the string name =");
gets(s);
strrev(s);
printf("\n the reverse string is = %s ",s);
getch();
}

OUTPUT:
PROGRAM 8

8) Write a program to concatenate two strings of different lengths .

#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
void main()
{
clrscr();
int len;
char s1[30],s2[30];
printf("\n\n Enter the first string name =");
gets(s1);
len=strlen(s1);
printf("\n\n the length of first string =%d",len);
printf("\n\n Enter the second string name =");
gets(s2);
len=strlen(s2);
printf("\n\n the length of second string =%d",len);
strcat(s1,s2);
printf("\n\n");
puts(s1);
getch();
}

OUTPUT:
PROGRAM 9

9)Represent a deck of playing cards using arrays

#include<stdio.h>

#include<conio.h>

void main()

clrscr();

char card[4];

int i;

card[1]='s';

card[2]='d';

card[3]='h';

card[4]='c';

printf("\n\n");

printf("\n Represent deck of cards :");

printf("\n\n");
printf("\n * /**\ (****
****) ** ");

printf("\n |*| /****\ (*******


*******) **** ");

printf("\n (*****) /******\


(****************) ** ** ** ");
printf("\n (*********) ********
(*************) ************** ");

printf("\n************* *******/
********* ********** ");

printf("\n (*********) *****/ *****


(******) ");

printf("\n *** ***/ ***


|||| ");

printf("\n ***** * *
|||||| ");

printf("\n\n");

printf("\n Spade(s) Diamond(d)


Heart(h) Club(c)
");

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

printf("\n");

printf(" %d%c",i,card[1]);

printf(" \t\t %d%c ",i,card[2]);

printf(" \t\t %d%c",i,card[3]);

printf(" \t\t %d%c",i,card[4]);

printf("\n");

getch();
}

OUTPUT :
PROGRAM 10
10) Write a program to check that the input string is a palindrome
or not.

#include<conio.h>

#include<stdio.h>

#include<string.h>

#include<math.h>

void main()

clrscr();

int n,i,len,mid;

char s[30];

printf("\n\n Enter the string name =");

gets(s);

len=strlen(s);

printf("\n length=%d",len);

strrev(s);

printf("\n reverse name=%s",s);;

printf("\n\n");

mid=len/2;

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

{
if(s[i]==s[len-i-1])

n=0;

else

n=1;

switch(n)

case 0 :printf("palindrome");

break;

case 1:printf("not pallindrome");

getch();

OUTPUT :
PROGRAM 11

11) C Program To Read The File And Print The Result On The
Screen
#include<stdio.h>

#include<conio.h>

main()

FILE *fp;

char ch;

clrscr();

if((fp=fopen("text1.dat","r"))==NULL)

printf("\n Cannot open file");

exit(1);

while((ch=fgetc(fp))!=EOF)

putchar(ch);

fclose(fp);

getch();

You might also like