SlideShare a Scribd company logo
MANNAR THIRUMALAI NAICKER COLLEGE
(AUTONOMOUS)
PASUMALAI, MADURAI – 625004.
DEPARTMENT OF COMPUTER SCIENCE (ARTIFICIAL
INTELLIGENCE)
PROGRAMMING in C LAB(23UAICP11)
PRACTICAL EXAMINATION
NOVEMBER 2024
MANNAR THIRUMALAI NAICKER COLLEGE (AUTONOMOUS)
MADURAI
DEPARTMENT OF COMPUTER SCIENCE (ARTIFICIAL
INTELLIGENCE)
BONAFIDE CERTIFICATE
NAME : REG_NO :
CLASS : I B. Sc (CS) AI SEMESTER : I
SUBJECT : Programming in C Lab SUB.CODE : 23UAICP11
This is to certify that this record is a bonafide work done by the above-
mentioned student. The certificate is awarded for the same.
HEAD OF THE DEPARTMENT STAFF IN-CHARGE
Submitted for Practical Examination held on _____________ at
Mannar Thirumalai Naicker College, Pasumalai, Madurai.
INTERNAL EXAMINER EXTERNAL EXAMINER
PROGRAMMING IN C LAB
CONTENTS
S.No. Date Title
Page
No.
Signature
1. ADDITION OF TWO INTEGERS
2. MULTIPLY TWO FLOATING NUMBERS
3. WRITE A CHARACTER AND STRING
4. SWAPPING NUMBERS
5. EVEN OR ODD
6. CHECK VOWEL OR CONSONANT
7. SIMPLE INTEREST CALCULATION
8. LARGEST AMONG THREE NUMBERS
9. SUM OF N NATURAL NUMBERS
10. FACTORIAL OF A NUMBER
11.
DISPLAY PRIME NUMBERS BETWEEN
TWO INTERVALS
12. SIMPLE CALCULATOR
13
SWAPPING TWO NUMBERS USING
FUNCTION
14
FACTORIAL OF N NUMBER USING
RECURSION
15
STRUCTURES FOR EMPLOYEE
INFORMATION
16 POINTERS
17 FILE OPERATIONS
1
EX. NO :1. ADDITION OF TWO INTEGERS
Aim:
To write a c program to add two integers.
Program:
#include <stdio.h>
#include<conio.h>
void main() {
int number1,number2,sum;
printf(“Enter two integers:”);
scanf("%d %d", &number1, &number2);
sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum);
getch();
}
Output:
Enter two integers: 5
7
5 + 7 = 12
Result: Thus the program has been successfully created.
2
EX.NO:2.MULTIPLY TWO FLOATING NUMBERS
Aim:
To write c program to multiply two floating numbers.
Program:
#include <stdio.h>
#include<conio.h>
void main() {
double a, b, product;
printf("Enter two numbers: ");
scanf("%lf %lf", &a, &b);
Product=a*b;
Printf(“Product=%2lf”,Product);
getch();
Output:
Enter two numbers :2.4
1.24
Product = 2.98
Result: Thus the program has been successfully created.
3
EX.NO:3.WRITE A CHARACTER AND STRING IN C
Aim:
To write a c program to read a single character, string and sentence as input.
1. Single character:
Program:
#include <stdio.h>
#include<conio.h>
void main(){
char ch;
printf(“Enter the name:”);
scanf(“%c”,&ch);
printf(“Output:%c”,ch);
getch();
}
Output:
Enter the name: Artificial Intelligence
Output:A
2. Reading a word in c
Program:
#include<stdio.h>
#include<conio.h>
void main(){
char word[100];
printf(“Enter the word:”);
scanf(“%s”,word);
4
printf(“output:%s”,word);
getch();
}
Output:
Enter the name: Artificial Intelligence
Output: Artificial Intelligence
Result: Thus the program has been successfully created.
5
EX.NO: 4. SWAPPING NUMBERS
Aim:
To write a c program to swap two numbers.
Program:
#include<stdio.h>
#include<conio.h>
void main() {
double first, second, temp;
printf("Enter first number: ");
scanf("%lf", &first);
printf("Enter second number: ");
scanf("%lf", &second);
temp = first;
first = second;
second = temp;
printf("nAfter swapping, first number = %.2lfn", first);
printf("After swapping, second number = %.2lf", second);
getch();
}
Output:
Enter first number: 1.20
Enter second number: 3.3
After swapping, first number = 3.30
After swapping, second number = 1.20
Result: Thus the program has been successfully created.
6
EX.NO: 5. EVEN OR ODD
Aim:
To write a program in c to check whether the number is even or odd.
Program:
#include <stdio.h>
#include <conio.h>
void main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);
getch();
}
Output:
Enter an integer:28
28 is even.
Enter an integer:35
35 is odd.
7
EX.NO:6.TO CHECK VOWEL OR CONSONANT
Aim:
To write a program in c to check the letter as vowel or consonant.
Program:
#include <stdio.h>
#include<conio.h>
void main() {
char c;
int lowercase_vowel, uppercase_vowel;
printf("Enter an alphabet: ");
scanf("%c", &c);
lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U')
if (lowercase_vowel || uppercase_vowel)
printf("%c is a vowel.", c);
else
printf("%c is a consonant.", c);
getch();
}
Output:
Enter an alphabet: y
y is a consonant.
Enter an alphabet: e
e is a vowel.
Result: Thus the program has been successfully created.
8
EX.NO:7. SIMPLE INTEREST CALCULATION
Aim:
To calculate the simple interest using C program.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int P,R,T;
double SI;
printf("Enter the principle:");
scanf("%d",&P);
printf("Enter the rate:");
scanf("%d",&R);
printf("Enter the time:");
scanf("%d",&T);
SI=(P*R*T)/100;
printf("The simple interest is %d",SI);
getch();
}
Output:
Enter the Principal: 1300
Enter the Rate: 12
Enter the Time: 2
The Simple Interest is:3120.0
Result: Thus the program has been successfully created.
9
EX.NO:8. LARGEST AMONG THREE NUMBERS
Aim:
To write c program to find the maximum number out of the three.
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int A,B,C;
printf("Enter the numbers A,B,and C:");
scanf("%d%d%d",&A,&B,&C);
if(A>=B&&A>=C)
printf("%d is the largest number:",A);
else if(B>=A&&B>=C)
printf("%d is the largest number:",B);
else
printf("%d is the largest number:",C);
getch();
}
Output:
Result: Thus the program has been successfully created.
10
EX .NO:9. SUM OF n NATURAL NUMBERS
Aim:
To write a c program for sum of n natural numbers .
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
Printf(“SUM OF N NATURAL NUMBERSn”);
Printf(“===========================n”);
int i,s-=0;
int n=10;
for (i=0;i<=n;i++)
{
s+=i;
}
printf("Sum= %d ",s);
getch();
}
OUTPUT:
Result: Thus the program has been successfully created.
11
EX NO:10 FACTORIAL OF A NUMBER
Aim:
To write a factorial number
Program:
#include <stdio.h>
#include <conio.h>
void main(){
int n,i;
unsigned long long fact=1;
clrscr();
printf("FACTORIAL");
printf("n---------n");
printf("Enter an integer :");
scanf("%d",&n);
if(n<0)
printf("Error!,Factorial of negative number does'nt exist");
else
for(i=1;i<=n;++i)
{
fact*=i;
}
printf("Factorial of %d=%llu",n,fact);
getch();
}
12
Output:
Result: Thus the program has been successfully created.
13
EX NO:11 DISPLAY PRIME NUMBERS BETWEEN TWO INTERVALS
Aim:
To display the prime numbers between two intervals
Program:
#include<stdio.h>
#include <conio.h>
void main()
{
clrscr();
int low ,high,i,flag;
printf("Enter two intervals :");
scanf("%d%d",&low,&high);
printf("Prime number between %d and %d are:",low,high);
while(low<high){
flag=0;
if(low<=1){
++low;
continue;
}
for(i=2;i<=low/2;++i)
{
if(low % i==0){
flag=1;
break;
}
}
14
if(flag==0)
printf("%d ",low);
++low;
}
getch();
}
Output:
Result:
Thus the program has been successfully created.
15
EX NO:12 SIMPLE CALCULATOR USING SWITCH STATEMENT
Aim:
To calculate the program using switch statement
Program:
#include<stdio.h>
#include<conio.h>
void main(){
clrscr();
char op;
double first,second;
printf("SIMPLE CALCULATOR");
printf("n------ ----------n");
printf("Enter an operator (+,-,*,/):");
scanf("%c",&op);
printf("Enter two operands:");
scanf("%lf%lf",&first,&second);
switch (op){
case'+':
printf("%1lf+%1lf=%1lf",first,second,first+second);
break;
case'-':
printf("%1lf-%1lf=%1lf",first,second,first-second);
break;
case'*':
printf("%1lf*%1lf=%1lf",first,second,first*second);
break;
16
case'/':
printf("%1lf/%1lf=%1lf",first,second,first/second);
break;
default:
printf("Error!Operator is not correct");
}
getch();
}
Output:
Result: Thus the program has been successfully created.
17
EX.NO: 13. SWAPPING TWO NUMBERS USING FUNCTION
Aim:
To write a c program to swap two numbers using function.
Program:
#include<stdio.h>
#include<conio.h>
void swap(int,int);
int main()
{
int a,b;
printf("Enter values for a and bn");
scanf("%d%d",&a,&b);
printf("nnBefore swapping: a = %d and b = %dn",a,b);
swap(a,b);
return 0;
}
void swap (int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("nAfter swapping:a=%d and b=%dn",x,y);
}
Output:
Result: Thus the program has been successfully created.
18
EX NO:14 FACTORIAL OF N NUMBER USING RECURSION
Aim:
To write a c program for factorial of n numbers using function
Program:
#include<stdio.h>
long factorial(int n)
{
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
void main()
{
int number;
long fact;
printf("Enter a number: ");
scanf("%d", &number);
fact = factorial(number);
printf("Factorial of %d is %ldn", number, fact);
return 0;
}
Output:
Enter a number: 6
Factorial of 5 is: 720
Result: Thus the program has been successfully created.
19
EX NO:15 STRUCTURES FOR EMPLOYEE DETAIL
AIM:
To write a c program to print employee information using structure
Program:
#include <stdio.h>
/*structure declaration*/
struct employee{
char name[30];
int empId;
float salary;
};
int main()
{
/*declare structure variable*/
struct employee emp;
/*read employee details*/
printf("nEnter details :n");
printf("Name :"); gets(emp.name);
printf("ID :"); scanf("%d",&emp.empId);
printf("Salary :"); scanf("%f",&emp.salary);
/*print employee details*/
printf("nEntered detail is:");
printf("Name: %s" ,emp.name);
printf("Id: %d" ,emp.empId);
printf("Salary: %fn",emp.salary);
return 0;
}
20
OUTPUT:
Result: Thus the program has been successfully created.
21
EX NO:16 PROGRAM FOR POINTERS
Aim:
To write a c program for pointers
Program:
#include <stdio.h>
void geeks()
{
int var = 10;
ble
int* ptr;
ptr = &var;
printf("Value at ptr = %p n", ptr);
printf("Value at var = %d n", var);
printf("Value at *ptr = %d n", *ptr);
}
// Driver program
int main()
{
geeks();
return 0;
}
Output:
Result: Thus the program has been successfully created.
22
EX NO:17 PROGRAM FOR FILE CREATION
Aim:
To Write a program to create a file called emp.rec and store information about a person, in
terms of his name, age and salary.
Program:
#include<stdio.h>
#include <conio.h>
#include<stdlib.h>
void main()
{
FILE *fptr;
char name[20];
int age;
float salary;
fptr = fopen("emp.rec", "w");
if (fptr == NULL)
{
printf("File does not exists n");
return;
}
printf("Enter the name n");
scanf("%s", name);
fprintf(fptr, "Name = %sn", name);
printf("Enter the agen");
scanf("%d", &age);
fprintf(fptr, "Age = %dn", age);
printf("Enter the salaryn");
scanf("%f", &salary);
fprintf(fptr, "Salary = %.2fn", salary);
23
fclose(fptr);
}
Output:
Result: Thus the program has been successfully created.

More Related Content

PPTX
Najmul
DOCX
PPTX
Introduction to Basic C programming 02
DOCX
B.Com 1year Lab programs
DOC
'C' language notes (a.p)
DOCX
Best C Programming Solution
PPTX
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
PPTX
C Language Programming Introduction Lecture
Najmul
Introduction to Basic C programming 02
B.Com 1year Lab programs
'C' language notes (a.p)
Best C Programming Solution
C BASICS.pptx FFDJF/,DKFF90DF SDPJKFJ[DSSIFLHDSHF
C Language Programming Introduction Lecture

Similar to Subject:Programming in C - Lab Programmes (20)

DOCX
Fuzail_File_C.docx
DOC
C-programs
PDF
C lab programs
PDF
C lab programs
PPTX
C language
PPTX
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
DOC
C important questions
DOC
Datastructure notes
DOCX
C lab manaual
DOCX
CS291(C Programming) assignment
DOCX
programs of c www.eakanchha.com
DOCX
Programming fundamentals
PDF
C programs
PPTX
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
DOC
c programing
DOCX
Cs291 assignment solution
DOCX
Practical File of C Language
DOCX
PDF
Common problems solving using c
Fuzail_File_C.docx
C-programs
C lab programs
C lab programs
C language
SIMPLE C PROGRAMS - SARASWATHI RAMALINGAM
C important questions
Datastructure notes
C lab manaual
CS291(C Programming) assignment
programs of c www.eakanchha.com
Programming fundamentals
C programs
Chapter 1_C Fundamentals_HS_Tech Yourself C.pptx
c programing
Cs291 assignment solution
Practical File of C Language
Common problems solving using c
Ad

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
ai tools demonstartion for schools and inter college
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Odoo POS Development Services by CandidRoot Solutions
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
AI in Product Development-omnex systems
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Migrate SBCGlobal Email to Yahoo Easily
ai tools demonstartion for schools and inter college
Upgrade and Innovation Strategies for SAP ERP Customers
How Creative Agencies Leverage Project Management Software.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Odoo POS Development Services by CandidRoot Solutions
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
VVF-Customer-Presentation2025-Ver1.9.pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Odoo Companies in India – Driving Business Transformation.pdf
top salesforce developer skills in 2025.pdf
Design an Analysis of Algorithms II-SECS-1021-03
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
AI in Product Development-omnex systems
Ad

Subject:Programming in C - Lab Programmes

  • 1. MANNAR THIRUMALAI NAICKER COLLEGE (AUTONOMOUS) PASUMALAI, MADURAI – 625004. DEPARTMENT OF COMPUTER SCIENCE (ARTIFICIAL INTELLIGENCE) PROGRAMMING in C LAB(23UAICP11) PRACTICAL EXAMINATION NOVEMBER 2024
  • 2. MANNAR THIRUMALAI NAICKER COLLEGE (AUTONOMOUS) MADURAI DEPARTMENT OF COMPUTER SCIENCE (ARTIFICIAL INTELLIGENCE) BONAFIDE CERTIFICATE NAME : REG_NO : CLASS : I B. Sc (CS) AI SEMESTER : I SUBJECT : Programming in C Lab SUB.CODE : 23UAICP11 This is to certify that this record is a bonafide work done by the above- mentioned student. The certificate is awarded for the same. HEAD OF THE DEPARTMENT STAFF IN-CHARGE Submitted for Practical Examination held on _____________ at Mannar Thirumalai Naicker College, Pasumalai, Madurai. INTERNAL EXAMINER EXTERNAL EXAMINER
  • 3. PROGRAMMING IN C LAB CONTENTS S.No. Date Title Page No. Signature 1. ADDITION OF TWO INTEGERS 2. MULTIPLY TWO FLOATING NUMBERS 3. WRITE A CHARACTER AND STRING 4. SWAPPING NUMBERS 5. EVEN OR ODD 6. CHECK VOWEL OR CONSONANT 7. SIMPLE INTEREST CALCULATION 8. LARGEST AMONG THREE NUMBERS 9. SUM OF N NATURAL NUMBERS 10. FACTORIAL OF A NUMBER 11. DISPLAY PRIME NUMBERS BETWEEN TWO INTERVALS 12. SIMPLE CALCULATOR 13 SWAPPING TWO NUMBERS USING FUNCTION 14 FACTORIAL OF N NUMBER USING RECURSION 15 STRUCTURES FOR EMPLOYEE INFORMATION 16 POINTERS 17 FILE OPERATIONS
  • 4. 1 EX. NO :1. ADDITION OF TWO INTEGERS Aim: To write a c program to add two integers. Program: #include <stdio.h> #include<conio.h> void main() { int number1,number2,sum; printf(“Enter two integers:”); scanf("%d %d", &number1, &number2); sum = number1 + number2; printf("%d + %d = %d", number1, number2, sum); getch(); } Output: Enter two integers: 5 7 5 + 7 = 12 Result: Thus the program has been successfully created.
  • 5. 2 EX.NO:2.MULTIPLY TWO FLOATING NUMBERS Aim: To write c program to multiply two floating numbers. Program: #include <stdio.h> #include<conio.h> void main() { double a, b, product; printf("Enter two numbers: "); scanf("%lf %lf", &a, &b); Product=a*b; Printf(“Product=%2lf”,Product); getch(); Output: Enter two numbers :2.4 1.24 Product = 2.98 Result: Thus the program has been successfully created.
  • 6. 3 EX.NO:3.WRITE A CHARACTER AND STRING IN C Aim: To write a c program to read a single character, string and sentence as input. 1. Single character: Program: #include <stdio.h> #include<conio.h> void main(){ char ch; printf(“Enter the name:”); scanf(“%c”,&ch); printf(“Output:%c”,ch); getch(); } Output: Enter the name: Artificial Intelligence Output:A 2. Reading a word in c Program: #include<stdio.h> #include<conio.h> void main(){ char word[100]; printf(“Enter the word:”); scanf(“%s”,word);
  • 7. 4 printf(“output:%s”,word); getch(); } Output: Enter the name: Artificial Intelligence Output: Artificial Intelligence Result: Thus the program has been successfully created.
  • 8. 5 EX.NO: 4. SWAPPING NUMBERS Aim: To write a c program to swap two numbers. Program: #include<stdio.h> #include<conio.h> void main() { double first, second, temp; printf("Enter first number: "); scanf("%lf", &first); printf("Enter second number: "); scanf("%lf", &second); temp = first; first = second; second = temp; printf("nAfter swapping, first number = %.2lfn", first); printf("After swapping, second number = %.2lf", second); getch(); } Output: Enter first number: 1.20 Enter second number: 3.3 After swapping, first number = 3.30 After swapping, second number = 1.20 Result: Thus the program has been successfully created.
  • 9. 6 EX.NO: 5. EVEN OR ODD Aim: To write a program in c to check whether the number is even or odd. Program: #include <stdio.h> #include <conio.h> void main() { int num; printf("Enter an integer: "); scanf("%d", &num); if(num % 2 == 0) printf("%d is even.", num); else printf("%d is odd.", num); getch(); } Output: Enter an integer:28 28 is even. Enter an integer:35 35 is odd.
  • 10. 7 EX.NO:6.TO CHECK VOWEL OR CONSONANT Aim: To write a program in c to check the letter as vowel or consonant. Program: #include <stdio.h> #include<conio.h> void main() { char c; int lowercase_vowel, uppercase_vowel; printf("Enter an alphabet: "); scanf("%c", &c); lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'); uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') if (lowercase_vowel || uppercase_vowel) printf("%c is a vowel.", c); else printf("%c is a consonant.", c); getch(); } Output: Enter an alphabet: y y is a consonant. Enter an alphabet: e e is a vowel. Result: Thus the program has been successfully created.
  • 11. 8 EX.NO:7. SIMPLE INTEREST CALCULATION Aim: To calculate the simple interest using C program. Program: #include<stdio.h> #include<conio.h> void main() { int P,R,T; double SI; printf("Enter the principle:"); scanf("%d",&P); printf("Enter the rate:"); scanf("%d",&R); printf("Enter the time:"); scanf("%d",&T); SI=(P*R*T)/100; printf("The simple interest is %d",SI); getch(); } Output: Enter the Principal: 1300 Enter the Rate: 12 Enter the Time: 2 The Simple Interest is:3120.0 Result: Thus the program has been successfully created.
  • 12. 9 EX.NO:8. LARGEST AMONG THREE NUMBERS Aim: To write c program to find the maximum number out of the three. Program: #include<stdio.h> #include<conio.h> void main() { int A,B,C; printf("Enter the numbers A,B,and C:"); scanf("%d%d%d",&A,&B,&C); if(A>=B&&A>=C) printf("%d is the largest number:",A); else if(B>=A&&B>=C) printf("%d is the largest number:",B); else printf("%d is the largest number:",C); getch(); } Output: Result: Thus the program has been successfully created.
  • 13. 10 EX .NO:9. SUM OF n NATURAL NUMBERS Aim: To write a c program for sum of n natural numbers . Program: #include<stdio.h> #include<conio.h> void main() { Printf(“SUM OF N NATURAL NUMBERSn”); Printf(“===========================n”); int i,s-=0; int n=10; for (i=0;i<=n;i++) { s+=i; } printf("Sum= %d ",s); getch(); } OUTPUT: Result: Thus the program has been successfully created.
  • 14. 11 EX NO:10 FACTORIAL OF A NUMBER Aim: To write a factorial number Program: #include <stdio.h> #include <conio.h> void main(){ int n,i; unsigned long long fact=1; clrscr(); printf("FACTORIAL"); printf("n---------n"); printf("Enter an integer :"); scanf("%d",&n); if(n<0) printf("Error!,Factorial of negative number does'nt exist"); else for(i=1;i<=n;++i) { fact*=i; } printf("Factorial of %d=%llu",n,fact); getch(); }
  • 15. 12 Output: Result: Thus the program has been successfully created.
  • 16. 13 EX NO:11 DISPLAY PRIME NUMBERS BETWEEN TWO INTERVALS Aim: To display the prime numbers between two intervals Program: #include<stdio.h> #include <conio.h> void main() { clrscr(); int low ,high,i,flag; printf("Enter two intervals :"); scanf("%d%d",&low,&high); printf("Prime number between %d and %d are:",low,high); while(low<high){ flag=0; if(low<=1){ ++low; continue; } for(i=2;i<=low/2;++i) { if(low % i==0){ flag=1; break; } }
  • 18. 15 EX NO:12 SIMPLE CALCULATOR USING SWITCH STATEMENT Aim: To calculate the program using switch statement Program: #include<stdio.h> #include<conio.h> void main(){ clrscr(); char op; double first,second; printf("SIMPLE CALCULATOR"); printf("n------ ----------n"); printf("Enter an operator (+,-,*,/):"); scanf("%c",&op); printf("Enter two operands:"); scanf("%lf%lf",&first,&second); switch (op){ case'+': printf("%1lf+%1lf=%1lf",first,second,first+second); break; case'-': printf("%1lf-%1lf=%1lf",first,second,first-second); break; case'*': printf("%1lf*%1lf=%1lf",first,second,first*second); break;
  • 19. 16 case'/': printf("%1lf/%1lf=%1lf",first,second,first/second); break; default: printf("Error!Operator is not correct"); } getch(); } Output: Result: Thus the program has been successfully created.
  • 20. 17 EX.NO: 13. SWAPPING TWO NUMBERS USING FUNCTION Aim: To write a c program to swap two numbers using function. Program: #include<stdio.h> #include<conio.h> void swap(int,int); int main() { int a,b; printf("Enter values for a and bn"); scanf("%d%d",&a,&b); printf("nnBefore swapping: a = %d and b = %dn",a,b); swap(a,b); return 0; } void swap (int x,int y) { int temp; temp=x; x=y; y=temp; printf("nAfter swapping:a=%d and b=%dn",x,y); } Output: Result: Thus the program has been successfully created.
  • 21. 18 EX NO:14 FACTORIAL OF N NUMBER USING RECURSION Aim: To write a c program for factorial of n numbers using function Program: #include<stdio.h> long factorial(int n) { if (n == 0) return 1; else return(n * factorial(n-1)); } void main() { int number; long fact; printf("Enter a number: "); scanf("%d", &number); fact = factorial(number); printf("Factorial of %d is %ldn", number, fact); return 0; } Output: Enter a number: 6 Factorial of 5 is: 720 Result: Thus the program has been successfully created.
  • 22. 19 EX NO:15 STRUCTURES FOR EMPLOYEE DETAIL AIM: To write a c program to print employee information using structure Program: #include <stdio.h> /*structure declaration*/ struct employee{ char name[30]; int empId; float salary; }; int main() { /*declare structure variable*/ struct employee emp; /*read employee details*/ printf("nEnter details :n"); printf("Name :"); gets(emp.name); printf("ID :"); scanf("%d",&emp.empId); printf("Salary :"); scanf("%f",&emp.salary); /*print employee details*/ printf("nEntered detail is:"); printf("Name: %s" ,emp.name); printf("Id: %d" ,emp.empId); printf("Salary: %fn",emp.salary); return 0; }
  • 23. 20 OUTPUT: Result: Thus the program has been successfully created.
  • 24. 21 EX NO:16 PROGRAM FOR POINTERS Aim: To write a c program for pointers Program: #include <stdio.h> void geeks() { int var = 10; ble int* ptr; ptr = &var; printf("Value at ptr = %p n", ptr); printf("Value at var = %d n", var); printf("Value at *ptr = %d n", *ptr); } // Driver program int main() { geeks(); return 0; } Output: Result: Thus the program has been successfully created.
  • 25. 22 EX NO:17 PROGRAM FOR FILE CREATION Aim: To Write a program to create a file called emp.rec and store information about a person, in terms of his name, age and salary. Program: #include<stdio.h> #include <conio.h> #include<stdlib.h> void main() { FILE *fptr; char name[20]; int age; float salary; fptr = fopen("emp.rec", "w"); if (fptr == NULL) { printf("File does not exists n"); return; } printf("Enter the name n"); scanf("%s", name); fprintf(fptr, "Name = %sn", name); printf("Enter the agen"); scanf("%d", &age); fprintf(fptr, "Age = %dn", age); printf("Enter the salaryn"); scanf("%f", &salary); fprintf(fptr, "Salary = %.2fn", salary);
  • 26. 23 fclose(fptr); } Output: Result: Thus the program has been successfully created.