Basic C Prgrams
Basic C Prgrams
Basic C Prgrams
Temperature Conversion
LOGIN: Balaji
/*TEMPERATURE CONVERSION*/
#include<stdio.h>
main()
{
float celcius,fahren,c,f;
clrscr();
printf(\n Tempterature Conversion);
printf(\nEnter the fahrenheit value:);
scanf(%f,&f);
celcius=(9.0/5.0)*(f-32);
printf(Celcius=%d,celcius);
printf(\nEnter the celcius value:);
scanf(%f,&c);
fahren=(9.0/5.0)*c+32;
printf(Fahrenheit=%d,fahren);
getch();
}
OUTPUT:
OUTPUT:
Enter the year 2000
It is a Leap Year
Enter the year 1995
It is Not a Leap Year
int age,height;
clrscr();
printf("\n Enter the age (in the range of 2 - 5 )and height ");
scanf("%d%d",&age,&height);
if(age<4)
{
if(height<55)
printf("\n the height is short");
else if((height >=55)&&(height < 75))
printf("\n the height is normal");
else
printf("\n the height is tall");
}
else
{
if(height<75)
printf("\n the height is short");
else if((height >=75)&&(height < 100))
printf("\n the height is normal");
else
printf("\n the height is tall");
}
getch();
}
OUTPUT:
Enter the age (in the range of 2 5) and height
2
65
the height is normal
Enter the age (in the range of 2 5) and height
5
120
the height is tall
}
number++;
}
}
OUTPUT:
Printing all Armstrong numbers between 1 and 500
Amstrong Number:1
Amstrong Number:153
Amstrong Number:370
Amstrong Number:371
printf(\n);
for(j=0;j<n;j++)
printf(\t%d,b[i][j]);
}
for(i=0;i<m;i++)
{
printf(\n);
for(j=0;j<n;j++)
{
c[i][j]=0;
for(k=0;k<m;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
printf(The multiplication of two matrixes);
for(i=0;i<m;i++)
{
printf(\n);
for(j=0;j<n;j++)
printf(\t%d,c[i][j]);
}
}
OUTPUT
Enter the Rows and Columns of A matrix... 3 3
Enter the Rows and Columns of B matrix... 3 3
Enter the elements of A matrix 1 2 3 4 5 6 7 8 9
Enter the elements of B matrix 1 2 3 4 5 6 7 8 9
The elements of A matrix
1
2
3
4
5
6
7
8
9
The elements of B matrix
1
2
3
4
5
6
7
8
9
The multiplication of two matrixes
30
36
42
66
81
96
102
126
150
char op;
clrscr();
printf("\n Arithemetic Operations using switch case");
printf("\nEnter the value of a and b");
scanf("%d%d",&a,&b);
printf("\nSelect the operation u want");
printf("\n+.Add\n-.Sub\n*.Mul");
printf("\n/.Div\n%.Mod");
printf("\nEnter ur choice");
scanf("%d",&op);
switch(op)
{
case +:
c=a+b;
printf("\nThe Sum is %d",c);
break;
case -:
c=a-b;
printf("\nThe difference is %d",c);
break;
case *:
c=a*b;
printf("\nThe product is %d",c);
break;
case /:
c=a/b;
printf("\nThe Quotient is %d",c);
break;
case %:
c=a%b;
printf("\nThe Reminder is %d",c);
break;
default:
printf("\nEnter the operator to perform Arithmetic operations");
break;
}
getch();
}
OUTPUT:
Arithemetic Operation
Enter the value of a and b 40 50
Select the operation u want
+.Add
-.Sub
*.Mul
/.Div
%.Mod
Enter ur choice*
#include<stdio.h>
#include<conio.h>
struct employ
{
char name[40];
int Emp_no;
float basic_sal;
float net_salary;
};
void main()
{
struct employ emp;
float hra,da,det;
clrscr();
printf("\nEmployee Details");
printf("\nEnter the emp name");
scanf("%s",emp.name);
printf("\nEnter the employee no");
scanf("%d",&emp.Emp_no);
printf("\nEnter the basic salary");
scanf("%f",&emp.basic_sal);
hra=((15*emp.basic_sal)/100);
da=((10*emp.basic_sal)/100);
det=((5*emp.basic_sal)/100);
emp.net_salary=emp.basic_sal+hra+da-det;
printf("\nEmployee name:%s",emp.name);
printf("\nEmployee no:%d",emp.Emp_no);
printf("\nEmployee Basic salary:%f",emp.basic_sal);
printf("\nHRA:%f",hra);
printf("\nDA:%f",da);
printf("\nDetection:%f",det);
printf("\nGross salary:%f",emp.net_salary);
getch();
}
OUTPUT:
Employee Details
Enter the employee name aaa
Enter the employee no1000
Enter the basic salary 5000
Employee name:aaa
Employee no:1000
Employee Basic salary:5000.000000
HRA:750.00000
DA:500.000000
Detection:250.000000
Gross salary:6500.000000
pt->grade=A;
}
printf(\n);
printf(NAME REGISTER-NO AVERAGE GRADE\n);
for(pt=stud;pt<stud+no;pt++)
{
printf(%-20s%-10s,pt->name,pt->regno);
printf(%10d \t %c\n,pt->avg,pt->grade);
}
}
OUTPUT:
Enter the number of the students
3
student[1] information:
Enter the name MUNI
Enter the roll no of the student 100
Enter the average value of the student 95
student[2] information:
Enter the name LAK
Enter the roll no of the student 200
Enter the average value of the student 55
student[3] information:
Enter the name RAJA
Enter the roll no of the student 300
Enter the average value of the student 25
NAME REGISTER-NO
AVERAGE
MUNI 100
95
A
LKA 200
55
B
RAJA
300
25
GRADE
x=x-y;
printf("\n After swapping the values of r1 = %d and r2 = %d",x,y);
}
OUTPUT:
Enter the two numbers
15 30
Before swapping the values of r1 =15 and r2 =30
After swapping the values of r1 =30 and r2 = 15
{
int num,a;
printf(Enter the number);
scanf(%d,&num);
a=recur(num);
printf(The factorial of the number %d is %d,num,a);
}
recur(int no)
{
int fact=1;
if(no==1)
return(1);
else
fact=no*recur(no-1);
}
OUTPUT:
Enter the number 5
The factorial of the number 5 is 120
class Demo
{
public static void main(String
args[])
{
int n=10;
System.out.println(n);
System.out.println(n+
+);
System.out.println(n);
}
}
Program
class Demo
Output
10
10
11
Output
{
args[])
+n);
}
10
11
11
System.out.println(n);
Prime Number
Logic: Prime Number are divisible by itself only.
Not divisible by any
Number
7%2=1
7%3=1
7%4=3
7%5=2
7%6=1
8%2=0
8%3=
8%4=
8%5=
8%6=
8%7=
9%2=1
9%3=0
9%4
9%5
9%6
9%7
9%8
Program
Output
Number");
}
}
next
sum
shifted to prev
shifted to next
13
13
...
13
...
...
Output
class Fibonacci
{
public static void main(String args[])
{
int prev, next, sum, n;
prev=next=1
for(n=1;n<=10;n++)
{
System.out.println(prev);
sum=prev+next;
prev=next;
next=sum;
}
}
}
1
1
2
3
5
8
13
...
sum
10
10
15
sum+n
15
21
21
28
28
36
36
45
45
10
55
Program
Output
class Sum10
{
public static void main(String args[])
{
int n, sum=0;
for(n=1;n<=10;n++)
{
sum+=n;
//or sum=sum+n;
}
System.out.println(sum);
}
}
55
n*n
sum
1*1
2*2
sum+n*n
3*3
14
14
4*4
30
30
5*5
55
55
6*6
91
91
7*7
140
140
8*8
204
204
9*9
285
285
10*10
385
Program
Output
class SumSq10
{
public static void main(String args[])
{
int n, sum=0;
for(n=1;n<=10;n++)
{
sum+=n;*n
//or sum=sum+n;*n
}
System.out.println(sum);
}
385
Factorial
Logic: Factorial of 5 = 5 x 4 x 3 x 2 x 1
prod
prod
prod*n
5
20
20
60
60
120
120
120
Program
Output
Output
Please Enter No 1: 5
Please Enter No 2: 23
Please Enter No 3: 14
Biggest No: 23
n3=scan.nextInt();
if(n1>n2 && n1>n3)
big=n1;
else if(n2>n1 && n2>n3)
big=n2;
else
big=n3;
System.out.println("Biggest No: " + big);
}
Output
Please Enter No 1: 5
Please Enter No 2: 23
Please Enter No 3: 14
Biggest No: 23
n2
temp
23
23
23
23
23
Program
Output
Please Enter No 1: 5
Please Enter No 2: 23
First No: 23
Second No: 5
}
}
n2
10
15
15
10
10
Program
Output
Please Enter No 1: 10
Please Enter No 2: 5
First No: 5
Second No: 10
Sum of Digits
Logic: 513 -> 5+1+3=9
N
res
513
sum
0
513%10
513/10
3
51
51%10
51/10
4
5
5%10
5/10
4
9
Program
Output
Please Enter No 1: 10
Please Enter No 2: 5
First No: 5
Second No: 10