0% found this document useful (0 votes)
86 views34 pages

Yogesh It Skills Lab File-1

The document contains details of 22 programs written in C programming language by a student. Each program is given a problem number, contains the code for the problem, and displays the output of the program. The programs cover basic concepts in C like input/output, arithmetic operations, conditional statements, loops, functions, arrays etc.

Uploaded by

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

Yogesh It Skills Lab File-1

The document contains details of 22 programs written in C programming language by a student. Each program is given a problem number, contains the code for the problem, and displays the output of the program. The programs cover basic concepts in C like input/output, arithmetic operations, conditional statements, loops, functions, arrays etc.

Uploaded by

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

1

INTEGRATED ACADEMY OF MANAGEMENT AND TECHNOLOGY,


GHAZIABAD

Computer Laboratory & Practical Work of C Programming

MBA(KMBN 151)

Submitted by: Submitted to:


YOGESH KUMAR Mrs.Suman parashari

Roll No: 217033

Integrated Academy of Management and Technology, Ghaziabad


NH-24,Near Dasna Crossing, Adhyatmik Nagar, Udhyog Kunj
Ghaziabad, Uttar Pradesh

S.no Practical Name Page Signature


2

No.

1 Program to print “Hello” on the Console. 3

2 Program to Display the sum of two given numbers. 4

3 Program to find out average and percentage of 3 given numbers. 5

4 Program to Calculate Simple Interest. 6

5 Program to find out the value of a given equation. 7

6 Program to find out largest of two given numbers. 8

7 Program to find out largest of three given numbers. 9

8 Program to find the gross salary of an employee (as per criteria). 10

9 Program to print all the Armstrong numbers. 11

10 Program to print Fibonacci series. 13

11 Program to print pascals triangle. 15

12 Program to find sum of first 50 numbers. 17

13 Program to print the table of a given number using function. 18

14 Program to find a given number is a prime number or not. 20

15 Program to find a given number is a perfect number or not. 21

16 Program to reverse a given digit. 22

17 Program to swap two numbers using third variable. 23

18 Program to swap two numbers without using third variable. 24

19 Program to find out factorial of a given number . 25

20 Program to reverse of a given numbert. 26

21 Program to create array of 5 elements and display them. 27

22 Program to print first 10 even numbers. (Using for & while loop) 28

23 Program to find sum both the diagonal of a 3X3 matrix. 30

24 Program to swap two numbers using Call by value method. 32

25 Program to swap two numbers using Call by reference method. 33


3

Problem 1- Program to print “Hello” on the Console.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
printf("Hello");
getch();
}

Output—
4

Problem 2- Program to Display the sum of two given numbers.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,sum=0;
printf("Enter the two numbers");
scanf("%d%d",&a,&b);
sum=sum+a+b;
printf("sum of two Numbers=%d",sum);
getch();
}

Output—
5
6

Problem 3- Program to find out average and percentage of 3 given numbers.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c,sum,avg,per;
clrscr();
printf("Enter The Number:");
scanf("%f%f%f",&a,&b,&c);
sum=sum+a+b+c;
avg=sum/3;
per=(sum/150)*100;
printf("avg=%f",avg);
printf("\t Percentage=%f",per);
getch();
}

Output-
7

Problem 4- Program to Calculate Simple Interest.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
float p,r,n,si;
printf("Enter the value of p,r,n");
scanf("%f%f%f",&p,&r,&n);
si=(p*r*n)/100;
printf("Simple interest=%f",si);
getch();
}

Output-
8

Problem 5- Program to find out the value of a given equation.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int s,area;
clrscr();
printf("Enter the side of the square");
scanf("%d",&s);
area=s*s;
printf("Area of the given square is=%d",area);
getch();
}

Output-
9

Problem 6- Program to find out largest of two given numbers.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the numbers");
scanf("%d%d",&a,&b);
if(a>b)
printf("%d is largest Num");
else
printf("%d is largest Num");
getch();
}

Output-
10

Problem 7- Program to find out largest of three given numbers.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the three Numbers");
scanf("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
printf("Largest Number is=%d",a);
else if(b>a&&b>c)
printf("Largest Number is=%d",b);
else
printf("Largest NUmber is=%d",c);
getch();
}

Output-
11

Problem 8- Program to find the gross salary of an employee (as per criteria).

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
float Basic,Da,Hra,Ta,Gross;
clrscr ();
printf("Enter The Besic Salary");
scanf("%f",&Basic);
Da=(20*Basic)/100;
Hra=(10*Basic)/100;
Ta=(10*Basic)/100;
Gross=Basic+Da+Hra+Ta;
printf("Gross=%f",Gross);
getch();
}

Output-
12

Problem 9- Program to find this Armstrong numbers or not.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0,temp;
clrscr();
printf("Enter the Number");
scanf("%d",&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf("Armstrong Number");
else
printf("Not Armstrong Number");
getch();
}

Output-
13
14

Problem 10- Program to print Fibonacci series.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int f1=0,f2=1,f3,k=0,length;
clrscr();
printf("Enter the length of the series:");
scanf("%d",&length);
printf("%d",f1);
printf("\t%d",f2);
k=2;
while(k<length)
{
f3=f1+f2;
printf("\t%d",f3);
k++;
f1=f2;
f2=f3;
}
getch();
}

Output-
15
16

Problem 11- Program to print pascals triangle.


Code-
#include<stdio.h>
int main()
{
int n;
printf(" Enter the number of rows:");
scanf("%d",&n);
for (int row=1; row<=n; row++)
{
int a=1;
for (int i=1; i<=row; i++)
{
printf("%d",a);
a=a*(row-i)/i;
}
printf("\n");
}
return 0;
}

Output-
17
18

Problem 12- Program to find sum of first 50 numbers.

Code-
#include <stdio.h>
void main()
{
int i,sum=0;
for(i=1;i<=50;i++)
{
sum= sum+i;
}
printf("sum of the first 50 number is: %d",sum);
}

Output-
19

Problem 13- Program to print the table of a given number using function.

Code-
#include <stdio.h>
void table(int num)
{
for(int i=1; i<=10;i++)
{
printf("\n%d * %d = %d\n",num,i,num*i);
}
}
void main()
{
int num;
printf("Enter the number: ");
scanf("%d",&num);
table(num);
}
20

Output-
21

Problem 14- Program to find a given number is a prime number or not.


Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,c=0;
printf("Enter The Number");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
if(num%i==0)
{
c++;
}
}
if(c==2)
printf("It Is Prime Nmber");
else
printf("It Is Not Prime NUmber");
getch();
}

Output-
22

Problem 15- Program to find a given number is a perfect number or not.

Code-
#include <stdio.h>
void main()
{
int i,num,sum=0;
printf("Enter a number: ");
scaf("%d",&num);
for(i=1;i<num;i++)
{
if(num%i==0)
sum=sum+i;
}
if(sum==num)
printf("The Entered number was Perfect");
else
printf("The Entered number was not Perfect");
}

Output-

Problem 16- Program to reverse a given digit.


23

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int n,num,rev=0;
clrscr();
printf("Enter the volume of n");
scanf("%d",&n);
while(n>0)
{
num=n%10;
rev=rev*10+num;
n=n/10;
}
printf("Rev=%d",rev);
getch();
}

Output-
24

Problem 17- Program to swap two numbers using third variable.


Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the Number");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("%d\t%d",a,b);
getch();
}

Output-
25

Problem 18- Program to swap two numbers without using third variable.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter The Number");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("Number After Swapping=%d\t%d", a,b);
getch();
}

Output-
26

Problem 19- Program to find out factorial of a given number .

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,fact=1;
clrscr();
printf("Enter The Number ");
scanf("%d",&num);
for(i=1;i<=num;i++)
fact=fact*i;
printf("Factorial Is=%d",fact);
getch();
}

Output-
27

Problem 20- Write a program to find area of rectangle using a function .

Code-
#include<stdio.h>
#include<conio.h>
int recar(int l,int b)
{
return(l*b);
}
void main()
{
int l,b,ar;
clrscr();
printf("\n Enter the length and breadth");
scanf("%d%d",&l,&b);
ar=recar(l,b);
printf("\n The area of Rectangle=%d",ar);
getch();
}

Output-
28

Problem 21- Program to create array of 5 elements and display them.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int num[5],i;
clrscr();
printf("\n Enter Array Element");
for(i=0;i<5;i++)
scanf("%d", &num[i]);
printf("\n Array Element Are:");
for(i=0;i<5;i++)
printf("\n%d",num[i]);
getch();
}

Output-
29

Problem 22- Program to print first 10 even numbers. (Using for & while loop)

Code-
#include <stdio.h>
void main()
{

//using for loop


for(int i=1;i<=20;i++)
{
if(i%2==0)
{
printf("%d",i);
}
}

//using while loop


int i=1;
while(i<=20)
{
if(i%2==0)
{
printf("%d",i);
}
i++;
}
}

Output-
30
31

Problem 23- Program to find sum both the diagonal of a 3X3 matrix.

Code-
#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],i,j,d1=0,d2=0,sum;
printf("Enter the element");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
scanf("%d",&a[i][j]);
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i==j)
d1=d1+a[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
if(i+j==2)
d2=d2+a[i][j];
}
32

}
sum=d1+d2;
printf("Sum of diagonal=%d",sum);
getch();
}

Output-
33

Problem 24- Program to swap two numbers using Call by value method.

Code-
#include <stdio.h>
void swap (int,int);
void main()
{
int i,j;
printf("Enter two number A and B: \n");
scanf("%d%d",&i,&j);
printf("Before swapping A=%d and B=%d\n",i,j);
swap(i,j);
}
void swap(int a,int b)
{
int temp;
temp=b;
b=a;
a=temp;
printf("After swapping A=%d and B=%d\n",a,b);
}

Output-
34

Problem 25-Program to swap two numbers. (Using call by reference)

Code-
#include <stdio.h>
void swap (int*,int*);
void main()
{
int *i,*j;
printf("Enter two number A and B: \n");
scanf("%d%d",&i,&j);
printf("Before swapping A=%d and B=%d\n",i,j);
swap(&i,&j);
printf("Before swapping A=%d and B=%d\n",i,j);
}
void swap(int *a,int *b)
{
int temp;
temp=*b;
*b=*a;
*a=temp;
}

Output-

You might also like