Yogesh It Skills Lab File-1
Yogesh It Skills Lab File-1
MBA(KMBN 151)
No.
22 Program to print first 10 even numbers. (Using for & while loop) 28
Code-
#include<stdio.h>
#include<conio.h>
void main()
{
printf("Hello");
getch();
}
Output—
4
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
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
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
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
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
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
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
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
Output-
17
18
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
Output-
22
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-
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
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
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
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
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()
{
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
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-