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

C program

Notes for c language

Uploaded by

jangrashyam2211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

C program

Notes for c language

Uploaded by

jangrashyam2211
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

PRACTICAL FILE

OF

FUNDAMENTALS OF COMPUTERS & PROGRAMMING (WITH C)

(CSEN1102)

BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE & ENGINEERING

Submitted By: Submitted To:

Name: SHYAM Ms. Anita Khandelwal

Roll no: A40322029 CSE Department

B.TECH 1st semester PDMU, Bahadurgarh

1|Page
INDEX

S. No. Experiment Date Signature

1 Write a program to calculate Simple Interest. 10/11/2022

2 Write a program to print Largest of Three numbers (If-Then-Else) 17/11/2022


Write a Program to print whether given number is Prime or not. 24/11/2022
3
Write Basic program illustrating Switch Case Statement. 01/12/2022
4
Write a program to print Largest of ten numbers (For Statement). 08/12/2022
5
Write a program to implement Matrix Multiplication. 15/12/2022
6
Write a program to print Fibonacci Series. 12/01/2023
7
Write a program to print Factorial of a number. 19/01/2023
8
Write a program to implement different String Functions. 02/02/2023
9
Write a program to check whether a string is palindrome or not. 16/02/2023
10

2|Page
Program -1
Aim: Write a program to calculate Simple Interest.

# include <stdio.h>

int main()

int p, time;

float rate;

float si;

printf ("enter value of principle: \n");

scanf ("%d",&p);

print f ("enter value of time: \n");

scan f ("%d",& time);

printf("enter rate: \n");

scanf("%f",& rate);

si = (p*rate*time)/100;

print f ("simple interest is %f",si);

return 0;

3|Page
OUTPUT:

4|Page
Program -2

Aim: Write a program to print largest of three numbers (if-then- else).

# include <stdio.h>

int main()

int n1,n2,n3;

printf ("enter three no. \n");

scanf ("%d %d %d",&n1,&n2,&n3); if(n1>n2 && n1>n3){

printf ("%d is the largest number\n",n1);

else if (n2>n1 && n2>n3){

printf ("%d is the largest number\n",n2);

else

printf ("%d is the largest number\n",n3);

return 0;

5|Page
OUTPUT:

6|Page
Program -3

Aim: Write a program to print whether given number is prime or not.


# include <stdio.h>

int main()

int n, m=0, flag=0;

printf ("Enter the number to check prime:\n");

scanf("%d",&n);

m=n/2;

for (int i=2; i<=m; i++ )

if (n%i==0)

printf ("number is not prime \n");

flag=1;

break;

if (flag==0){

printf("number is prime \n");

return 0;

7|Page
Output:

8|Page
Program -4

Aim: Write basic programs illustrating Switch Case statement .

# include <stdio.h>

int main()

int n1,n2;

int choice;

int A,S,M,D;

printf("enter the 1st number: \n"); scanf("%d",&n1);

printf("enter the 2nd number: \n"); scanf("%d",&n2);

printf("\nenter choice: \n");

printf("\n1.addition\n2.substracion\n3.multiplication\n4.division\n");

scanf("%d",&choice);

switch(choice)

case 1: A=n1+n2;

printf("Addition is %d",A);

break;

case 2: S=n1-n2;

printf("Subtraction is %d",S);

break;

9|Page
case 3: M = n1*n2;

printf ("multiplicaion is %d",M);

break;

case 4: D= n1/n2;

printf ("division is %d",D);

break;

default : printf ("\ninvalid choice");

return 0;

10 | P a g e
Output:

11 | P a g e
Program -5

Aim: Write a program to print largest of ten numbers (for statement).


#include<stdio.h>

int main()

int a[10];

int i;

int greatest;

printf("enter the value: "); for (i=0;i<10;i++)

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

greatest = a[10];

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

if (a[i]>greatest)

greatest = a[i];

printf("greatest of ten numbers is :%d \n",greatest);

return 0;

12 | P a g e
OUTPUT:

13 | P a g e
Program -6
Aim : Write a program to implement matrix multiplication.
#include<stdio.h>

#include<stdlib.h>

int main()

int a[10][10],b[10][10],c[10][10]; int r1,c1,r2,c2;

printf("enter the row and column of 1st matrix:\n"); scanf("%d %d",&r1,&c1);

printf("enter the row and column of 2nd matrix: \n"); scanf("%d %d",&r2,&c2);

if (c1!=r2){

printf("\n matrix is not multiplicable \n");

exit(0);

printf("enter the element of 1st matrix: \n"); for (int i=0;i<r1;i++)

for (int j=0;j<c1;j++){

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

printf("enter the element of 2nd matrix: \n");

for (int i=0;i<r2;i++){

for (int j=0;j<c2;j++){

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

14 | P a g e
}

printf("\n1st matrix:\n");

for(int i=0;i<r1;i++){

for (int j=0;j<c1;j++)

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

printf("\n");

printf("\n2st matrix:\n");

for(int i=0;i<r2;i++){

for (int j=0;j<c2;j++){

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

printf("\n");

for (int i=0;i<r1;i++){

for(int j=0;j<c2;j++){

int s=0;

for(int k=0;k<c1;k++){

s+=a[i][k]*b[k][j];

c[i][j]=s;

printf("\nproduct of matrix\n"); for(int i=0;i<r1;i++){

for (int j=0;j<c2;j++){


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

15 | P a g e
}

printf("\n");
}

return 0;
}

16 | P a g e
OUTPUT:

OUTPUT:

17 | P a g e
Program -7

Aim: Write a program to print Fibonacci Series.


#include<stdio.h>

int main()

int n1=0,n2=1,n3,i,n;

printf("enter the term of fiboncci no. \n");

scanf("%d\n",&n);

printf("%d %d",n1,n2);

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

n3=n1+n2;

printf(" %d",n3);

n1=n2;

n2=n3;

return 0;

18 | P a g e
OUTPUT :

19 | P a g e
Program -8
Aim: Write a program to print factorial of a number.

#include<stdio.h>

int main()

int fact=1,n;

printf("Enter the number to find its factorial: \n");

scanf("%d",&n);

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

fact*=i;

printf("factorial of entered %d number is: %d",n,fact);

return 0;

20 | P a g e
OUTPUT:

21 | P a g e
Program -9

Aim: Write a program to implement different string functions


#include <stdio.h>

#include <string.h>

int main()

char a[20]="Program";

/*strlen(a)*/

char b[20]={'P','r','o','g','r','a','m','\0'};

printf("Length of string a = %zu \n",strlen(a));

printf("Length of string b = %zu \n",strlen(b));

char str1[100] = "This is ", str2[] = "good boy";

/strcat/

strcat(str1, str2);

puts(str1);

puts(str2);

return 0;

22 | P a g e
OUTPUT:

OUTPUT:

23 | P a g e
Program -10
Aim: Write a program to check whether a string is palindrome or not.

#include <stdio.h>

#include <string.h>

int main()

char string1[20];

int i, length;

int flag = 0;

printf("Enter a string:");

scanf("%s", string1);

length = strlen(string1);

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

if(string1[i] !=

string1[length-i-1])

flag = 1;

break;

if (flag)

24 | P a g e
{

printf ("%s is not a palindrome", string1);

else

printf ("%s is a palindrome", string1);

return 0;

25 | P a g e
OUTPUT:

26 | P a g e

You might also like