PRACTICAL – 01
1)
1.1 WAP TO DISPLAY “HELLO WORLD”.
CODE:-
#include<stdio.h>
#include<conio.h>
Int main()
{
Printf(“Hello World”);
Return 0;
}
1.2 WAP TO CALCULATE THE SIMPLE INTEREST. (FORMULA
P*R*N/100)
CODE:-
#include <stdio.h>
#include <conio.h>
Int main()
{
Float P,R,N;
1
Printf(“ENTER PRINCIPLE VALUE:-“);
Scanf(“%f”,&P);
Printf(“\nENTER RATE VALUE:-“);
Scanf(“%f”,&R);
Printf(“\nENTER YEAR:-“);
Scanf(“%f”,&N);
Float SI = (P*R*N) / 100;
Printf(“Simple Interest = %f\n”, SI);
Return 0;
}
1.3 WAP TO PROGRAM TO SWAP TWO NUMBERS USING THIRD
VAIRABLE
CODE :-
#include<stdio.h>
#include<conio.h>
Int main()
{
Int a=73,b=29,c;
C=a;
A=b;
2
B=c;
Printf(“%d”,a);
Printf(“%d”,b);
Return 0;
}
1.4 WAP TO PRINT PRIME NUMBER FROM 1 TO N
(NUMBER).
CODE :-
#include<stdio.h>
#include<conio.h>
Int main()
{
Int n,i,j;
Printf(“enter a number:”);
Scanf(“%d”,&n);
Printf(“prime number from 1 to %d are:\n”,n);
3
For(i=2;i<=n;i++){
Int prime=1;
For(j=2;j*j<=i;j++) {
If(i % j==0){
Prime=0;
Break;
}
}
If(prime){
Printf(“%d\n”,i);
}
}
Printf(“\n”);
Return 0;
}
4
1.5 WAP TO FIND OUT THE FACTORIAL OF A NUMBER.
CODE :-
#include<stdio.h>
#include<conio.h>
Int main()
{
Int n,i;
Int factorial=1;
Printf(“enter a number:”);
Scanf(“%d”,&n);
For(i=1;i<=n;i++)
5
{
Factorial*=i; //multiply factorial by i
}
Printf(“factorial of %d=%d\n”,n,factorial);
Printf(“end of the program”);
Return 0;
}
1.6 WAP TO PERFORM
ADDTION,MULTIPLICATION,DIVISION,AND
SUBTRACTION ON GIVEN TWO NUMBERS
#include<stdio.h>
#include<conio.h>
Int main()
{
Int n1,n2;
Printf(“enter first number:”);
Scanf(“%d”,&n1);
6
Printf(“\nenter second number:”);
Scanf(“%d”,&n2);
Int sum = n1+n2;
Int sub = n1-n2;
Int mul = n1*n2;
Int div = n1/n2;
Printf(“\nyour addition is :%d”,sum);
Printf(“\nyour subtraction is :%d”,sub);
Printf(“\nyour multiplication is :%d”,mul);
Printf(“\nyour division is :%d”,div);
Printf(“\nend of the program!!”);
Return 0; }
7
1.7 WAP TO FIND OUT THE AREA OF CIRCLE.
CODE :-
//to find area of circle
#include<stdio.h>
#include<conio.h>
Int main()
{
Float area,r;
Printf(“enter your redius of circle:”);
Scanf(“%f”,&r);
Area=3.14*r*r;
Printf(“your area of circle is:%f”,area);
Return 0;
1.8 WAP TO FIND THE GREATEST NUMBER AMONG THREE
8
NUMBERS
CODE :-
#include<stdio.h>
#include<conio.h>
Int main()
{
Int n1,n2,n3;
Printf(“enter three numbers:”);
Scanf(“%d %d %d”,&n1,&n2,&n3);
If(n1>=n2 && n1>=n3)
{
Printf(“the greatest number is:%d\n”,n1);
}
Else if(n2>=n1 && n2>=n3)
{
Printf(“the gratest number is:%d\n”,n2);
}
Else
{
Printf(“the greatest number is:%d\n”,n3);
}
Return 0;
}
9
1.9 WAP TO CHECK WHETHER A NUMBER IS PALINDROME OR
NOT.
CODE :-
#include<stdio.h>
#include<conio.h>
Int main()
{
Int num, reversed = 0, remainder, original;
Printf(“Enter a number: “);
Scanf(“%d”, &num);
Original = num;
While (num != 0) {
Remainder = num % 10;
Reversed = reversed * 10 + remainder;
Num /= 10;
}
10
If (original == reversed)
{
Printf(“%d is a palindrome number.\n”, original);
}
Else
{
Printf(“%d is not a palindrome number.\n”, original);
}
Return 0;
}
1.10 WAP TO CHECK THAT ENTERED YEAR IS LEAP YEAR OR
NOT.
CODE :-
#include<stdio.h>
#include<conio.h>
Int main()
{
Int year;
11
Printf(“Enter a year: “);
Scanf(“%d”, &year);
If ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
Printf(“%d is a leap year.\n”, year);
} else {
Printf(“%d is not a leap year.\n”, year);
}
Return 0;
}
1.11 WAP TO CHECK WHETHER A CHARACTER IS A VOWEL OR
CONSONANT. (USE SWITCH CASE)
CODE:-
#include<stdio.h>
#include<conio.h>
Int main()
{
Char ch;
Printf(“Enter a character: “);
12
Scanf(“%c”, &ch);
// Convert character to lowercase for case-insensitive comparison
Ch = tolower(ch);
If (ch == ‘a’ || ch == ‘e’ || ch == ‘i’ || ch == ‘o’ || ch == ‘u’)
{
Printf(“%c is a vowel.\n”, ch);
}
Else if ((ch >= ‘a’ && ch <= ‘z’))
{
Printf(“%c is a consonant.\n”, ch);
}
Else
{
Printf(“Please enter a valid alphabet character.\n”);
}
Return 0;
}
13
1.12 WAP TO PRINT THE HALF PYRAMID.
CODE :-
#include<stdio.h>
#include<conio.h>
Int main()
{
Int i, j, n;
Printf(“Enter the number of rows: “);
Scanf(“%d”, &n);
For(i = 1; i <= n; i++)
{
// Loop to print the stars in each row
For(j = 1; j <= i; j++)
{
Printf(“*”);
}
// Move to the next line after each row
Printf(“\n”);
}
Return 0;
}
14
1.13 WAP TO PRINT THE DIAMOND PATTERN.
CODE :-
#include<stdio.h>
#include<conio.h>
Int main()
{
Int n, i, j, space;
Printf(“Enter the number of rows for the diamond: “);
Scanf(“%d”, &n);
Space = n – 1;
// Printing the upper half of the diamond
For(i = 1; i <= n; i++)
{
15
// Printing leading spaces
For(j = 1; j <= space; j++)
Printf(“ “);
// Printing stars
For(j = 1; j <= (2 * i – 1); j++)
Printf(“*”);
Printf(“\n”);
Space--;
}
Space = 1;
// Printing the lower half of the diamond
For(i = 1; i <= n – 1; i++) {
// Printing leading spaces
For(j = 1; j <= space; j++)
Printf(“ “);
// Printing stars
For(j = 1; j <= (2 * (n – i) – 1); j++)
Printf(“*”);
Printf(“\n”);
Space++;
}
Return 0;
}
16
1.14 . WAP TO PRINT THE FOLLOWING INFORMATION OF AN
EMPLOYEE USING STRUCTURE. EMPLOYEE DETAILS:
(DISPLAY
MINIMUM 5 EMPLOYEE DETAILS)
CODE:-
#include<stdio.h>
#include<conio.h>
// Defining the structure for employee details
Struct Employee
{
Int id;
Char name[50];
Char address[100];
Float salary;
17
};
Int main()
{
Int i;
Struct Employee emp[5];
// Inputting details for 5 employees
For(i = 0; i < 5; i++)
{
Printf(“Enter details for Employee %d:\n”, i+1);
Printf(“Enter Employee ID: “);
Scanf(“%d”, &emp[i].id);
Printf(“Enter Employee Name: “);
Scanf(“ %[^\n]%*c”, emp[i].name); // This allows to input string
with spaces
Printf(“Enter Employee Address: “);
Scanf(“ %[^\n]%*c”, emp[i].address);
Printf(“Enter Employee Salary: “);
Scanf(“%f”, &emp[i].salary);
Printf(“\n”);
18
}
// Displaying employee details
Printf(“Employee Details:\n”);
For(i = 0; i < 5; i++) {
Printf(“Employee %d:\n”, i+1);
Printf(“ID: %d\n”, emp[i].id);
Printf(“Name: %s\n”, emp[i].name);
Printf(“Address: %s\n”, emp[i].address);
Printf(“Salary: %.2f\n”, emp[i].salary);
Printf(“\n”);
}
Return 0;
}
19
20
1.15 . CREATE A FUNCTION TO PRINT
ADDITION,SUBTRACTION,
MULTIPLICATION, DIVISION ARITHMETIC OPERATION OF
TWO
INPUTTED NUMBERS
CODE:-
21
#include<stdio.h>
#include<conio.h>
Void arithmeticOperations(float num1, float num2) {
Printf(“Addition: %.2f + %.2f = %.2f\n”, num1, num2, num1 +
num2);
Printf(“Subtraction: %.2f - %.2f = %.2f\n”, num1, num2, num1 –
num2);
Printf(“Multiplication: %.2f * %.2f = %.2f\n”, num1, num2, num1 *
num2);
If (num2 != 0)
{
Printf(“Division: %.2f / %.2f = %.2f\n”, num1, num2, num1 /
num2);
} else
{
Printf(“Division by zero is not allowed.\n”);
}
}
Int main()
{
Float num1, num2;
Printf(“Enter two numbers:\n”);
Scanf(“%f %f”, &num1, &num2);
22
// Calling the function to perform arithmetic operations
arithmeticOperations(num1, num2);
return 0;
}
23