SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
1
2
(Basics)
1. WAP to print text on the screen.
2. WAP to check if number is odd or even.
3. WAP to check which of the two entered numbers is greater.
4. WAP to check whether entered number is a leap year or not.
5. WAP to convert temperature in Fahrenheit to Celsius.
(Looping)
6. WAP to display the multiplication table of entered number.
7. WAP to check if number is Palindrome or not.
8. WAP to check if number is an Angstrom number or not.
9. WAP to check if number is a prime or not.
10.WAP to find the sum of Fibonacci series.
(Arrays)
11.WAP to find the sum and average of 10 numbers using arrays.
12.WAP to add elements of two 3x3 matrices.
(Pointers & Functions)
13.WAP to understand pointers.
14.WAP to swap two numbers.
15.WAP to Swap two numbers using pointers (and functions).
16.WAP to find the factorial of a number using recursive function.
(Structures)
17.WAP using structures to input and display details of student.
(Strings)
18.WAP to enter two strings and get them to display.
(Data File Handling)
19.WAP to enter and retrieve a character from a file.
20.WAP to copy the contents of one file to another.
3
4
5
6
7
8
9
10
11
12
13
14
16
17
18
19
20
21
22
23
3
Write a Program to display text on screen.
SOURCE CODE:
1
2
3
4
5
6
7
#include<stdio.h>
int main()
{
printf(" Welcome to Neil's Practical File. XD ");
return 0;
}
OUTPUT:
Welcome to Neil's Practical File. XD
4
Write a Program to check if number is odd or even.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<stdio.h>
int main()
{
int num;
printf(" Enter the number: ");
scanf(" %d ", &num);
if(num%2==0)
printf("n Number is Even. ");
else
printf("n Number is Odd. ");
return 0;
}
OUTPUT:
Enter the number: 5
Number is Odd.
Enter the number: 8
Number is Even.
5
Write a Program to check which of the two entered
numbers is greater.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
main ()
{
int a,b,c;
printf("n Enter two Numbers: ");
scanf("%d%d",&a,&b);
c=a ? b:a ;
printf("n Greater number of the two is : %d n",c);
}
OUTPUT:
Enter two Numbers: 5 357
Greater number of the two is : 357
6
Write a Program to check whether entered number is a
leap year or not.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
main()
{
int Y;
printf("Enter any year: ");
scanf("%d", &Y);
if((Y%4==0))
printf("nThe entered year is a Leap Year.");
else
printf("nThe entered year is not a Leap Year.");
return 0;
}
OUTPUT:
Enter any year: 1991
The entered year is not a Leap Year.
Enter any year: 1994
The entered year is a Leap Year.
7
Write a Program to convert temperature in Fahrenheit
to Celsius.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <stdio.h>
int main()
{
float Tf, Tc;
printf("Enter temperature in Farenheit: ");
scanf("%f", &Tf);
Tc=((Tf-32)*(5.0/9.0));
printf("The temperature in Celcius is %f", Tc);
return 0;
}
OUTPUT:
Enter temperature in Farenheit: 98.6
The temperature in Celcius is 37.000000
8
Write a Program to display the multiplication table of
entered number.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<stdio.h>
int main()
{
int i,n,a;
printf("nEnter the number whose table is to be printed : ");
scanf("%d",&n);
for(i=1;i<11;i++)
{
a=n*i;
printf("%dx%i=%d n",n,i,a);
}
return 0;
}
OUTPUT:
Enter the number whose table is to be printed : 5
5x1=5
5x2=10
5x3=15
5x4=20
5x5=25
5x6=30
5x7=35
5x8=40
5x9=45
5x10=50
9
Write a Program to check if number is Palindrome or
not.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
main()
{
int num; //number inputted by user
int n; //temporary storage
int rev=0; //stores the reverse of that number
int digit; //stores the individual digits
printf(" Enter the number to check if it's Palindrome or not:
");
scanf("%d", &num);
n=num;
do
{
digit=n%10;
rev=(rev*10)+digit;
n=n/10;
}
while(n>0);
if(rev==num)
{
printf("n The number is a palindrome. ");
}
else
{
printf("n The number is not a palindrome. ");
}
}
OUTPUT:
Enter the number to check if it's Palindrome or not: 121
The number is a palindrome.
Enter the number to check if it's Palindrome or not: 153
The number is not a palindrome.
10
Write a Program to check if number is an Angstrom
number or not.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
main()
{
int num; //number inputted by user
int n; //temporary storage
int A=0; //stores the sum of the cube of the digits
int digit; //stores the individual digits
printf(" Enter the number to check if it's Angstrom or not:
");
scanf("%d", &num);
n=num;
do
{
digit=n%10;
A+=(digit*digit*digit);
n=n/10;
}
while(n>0);
if(A==num)
{
printf("n The number is an Angstrom number. ");
}
else
{
printf("n The number is not an Angstrom number. ");
}
}
OUTPUT:
Enter the number to check if it's Angstrom or not: 121
The number is not an Angstrom number.
Enter the number to check if it's Angstrom or not: 153
The number is an Angstrom number.
11
Write a Program to check if number is a prime or not.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<stdio.h>
int main()
{
int num;
printf("n Enter the number to check whether prime or not:
");
scanf(" %d ",&num);
if( num==0 || num==1 )
{
printf("n The number is not prime. ");
}
else
{
int i=0;
int flag=1; // 1 if prime, 0 if not prime
for(i=2; i<num; i++)
{
if(num%i==0)
{
flag=0;
break;
}
}
if(flag==1)
{
printf("n The number is prime. ");
}
else
{
printf("n The number is not prime ");
}
}return 0;
}
OUTPUT:
Enter the number to check whether prime or not: 1
The number is not prime.
Enter the number to check whether prime or not: 5
The number is prime.
Enter the number to check whether prime or not: 12
The number is not prime.
12
Write a Program to find the sum of Fibonacci series.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<stdio.h>
main()
{
int sum=0;
int n;
printf("n Till which term should the Fibonacci series be
found: ");
scanf(" %d ", &n);
printf("n The Fibonacci Series: n ");
if( n==0 )
{
printf(" None ");
}
else if( n==1 )
{
printf("0");
}
else
{
int i,temp;
int first=0,second=1;
//2nd term
printf("%d + %d ",first,second);
sum+=second;
for(i=3; i<=n; i++) //3rd term onwards
{
temp=second;
second=second+first;
first=temp;
printf("+ %d ",second);
sum+=second;
}
}
printf("n Sum = %d",sum);
}
OUTPUT:
Till which term should the Fibonacci series be found: 8
The Fibonacci Series:
0 + 1 + 1 + 2 + 3 + 5 + 8 + 13
Sum = 33
13
Write a Program to find the sum and average of 10
numbers using arrays.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
int main()
{
//INITIAL DECLARATIONS
int x[10];
int sum=0;
float avg;
int i;
//INPUT
printf("n Enter the 10 numbers: n ");
for(i=0; i<10; i++)
{
scanf(" %d ", &x[i]); // *Note the & for array element
}
//CALCULATIONS
for(i=0; i<10; i++)
{
sum+=x[i];
}
avg=sum/10.0;
//OUTPUT
printf("n The Sum of the numbers: %d ",sum);
printf("n The Average of the numbers: %f n",avg);
return 0;
}
OUTPUT:
Enter the 10 numbers:
1 2 3 4 5 6 7 8 9 10
The Sum of the numbers: 55
The Average of the numbers: 5.500000
14
Write a Program to add elements of two 3x3 matrices.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<stdio.h>
int main()
{
int A[3][3], B[3][3];
int i,j;
//INPUT of MATRIX/ 2D ARRAY A
printf("n Enter the elements of matrix A: n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf(" %d ", &A[i][j]);
}
}
//INPUT of MATRIX/ 2D ARRAY B
printf("n Enter the elements of matrix B: n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
scanf(" %d ", &B[i][j]);
}
}
//ADDING THE TWO MATRICES
printf("n Adding matrices A and B = matrix C ");
int C[3][3];
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}
//OUTPUT
printf("n Matrix C is: n");
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
printf(" %d ", C[i][j]);
}
printf("n");
}
return 0;
}
15
OUTPUT:
Enter the elements of matrix A:
1 2 3
1 2 3
3 2 1
Enter the elements of matrix B:
3 2 1
3 2 1
1 2 3
Adding matrices A and B = matrix C
Matrix C is:
4 4 4
4 4 4
4 4 4
16
Write a Program to understand pointers.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
main()
{
int a,*p;
printf("Enter an integer: ");
scanf("%d",&a);
p = &a;
printf("nAddress of a: %u", &a);
printf("nnAddress of p: %u", &p);
printf("nnValue of p: %d", p);
printf("nnValue of a: %d", a);
printf("nnValue of a: %d", *p);
}
OUTPUT:
Enter an integer: 7
Address of a: 3219592736
Address of p: 3219592732
Value of p: -1075374560
Value of a: 7
Value of a: 7
17
Write a Program using structures to input and display
details of student.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <stdio.h>
struct student
{
char name[20];
float marks;
int age;
}b1, b2;
main()
{
printf("n Enter Names, Marks & Age of the students:
n");
scanf("%s %f %d",&b1.name,&b1.marks,&b1.age);
scanf("%s %f %d",&b2.name,&b2.marks,&b2.age);
printf("n This is what you have entered: n");
printf("n %s %f %d ",b1.name,b1.marks,b1.age);
printf("n %s %f %d ",b2.name,b2.marks,b2.age);
}
OUTPUT:
Enter Names, Marks & Age of the students:
Neil 94 18
Bugger 0 100
This is what you have entered:
Neil 94.000000 18
Bugger 0.000000 100
18
Write a program to swap two numbers.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<stdio.h>
int main()
{
int a,b;
printf("n Enter the value of A: ");
scanf("%d",&a);
printf(" Enter the value of B: ");
scanf("%d",&b);
//Swapping:
int temp;
temp=a;
a=b;
b=temp;
printf("n After Swapping... n");
printf(" A: %d", a);
printf("n B: %d", b);
return 0;
}
OUTPUT
Enter the value of A: 5
Enter the value of B: 10
After Swapping...
A: 10
B: 5
19
Write a Program to Swap two numbers using pointers.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<stdio.h>
void Swap(int *a, int *b)
{ // *Note the syntax of pointers for arguments
//Swapping:
int temp;
temp=*a; // *(pointer_variable) to access the value
*a=*b;
*b=temp;
}
int main()
{
int a,b;
printf("n Enter the value of A: ");
scanf("%d",&a);
printf(" Enter the value of B: ");
scanf("%d",&b);
Swap(&a,&b); // *Note the & during such a call
printf("n After Swapping... n");
printf(" A: %d", a);
printf("n B: %d", b);
return 0;
}
OUTPUT:
Enter the value of A: 4
Enter the value of B: 9
After Swapping...
A: 9
B: 4
20
Write a Program to find the factorial of a number using
recursive function.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include<stdio.h>
int fact(int f)
{
if( f==1 || f==0)
{ return 1; }
else
{
f=f*fact(f-1);
return f;
}
}
main()
{
int num;
int factorial;
printf(" Enter the number whose factorial needs to be found:
");
scanf(" %d ", &num);
factorial=fact(num);
printf("n The factorial of %d is %d. ",num,factorial);
}
OUTPUT:
Enter the number whose factorial needs to be found: 0
The factorial of 0 is 1.
Enter the number whose factorial needs to be found: 4
The factorial of 4 is 24.
21
Write a Program to enter two strings and get them to
display.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdio.h>
int main()
{
char S1[20];
char S2[20]; //the datatype string doesn't exist in C.
//method 1: can only take one word at a time (till spaces).
printf("n Enter the first string: ");
scanf(" %s ", S1);
//method 2: can take whole line including spaces.
printf(" Enter the second string: ");
gets(S2);
printf("n The Strings are:n 1st: %sn 2nd: ",S1);
puts(S2);
return 0;
}
OUTPUT:
Enter the first string: Hello
Enter the second string: World
The Strings are:
1st: Hello
2nd: World
Enter the first string: New York
Enter the second string:
The Strings are:
1st: New
2nd: York
22
Write a Program to enter and retrieve a character from
a file using DATA FILE HANDLING.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdio.h>
main()
{
char ch;
FILE *file;
file = fopen("abc.txt", "w");
printf("nEnter any character into FILE: ");
scanf("%c", &ch);
putc(ch, file);
fclose(file);
file = fopen("abc.txt", "r");
ch = getc(file);
printf("nEntered Character from FILE: %c", ch);
}
OUTPUT:
Enter any character into FILE: Y
Entered Character from FILE: Y
23
Write a program to copy the contents of one file to
another using DATA FILE HANDLING.
SOURCE CODE:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>
main()
{
char ch;
FILE *fp1, *fp2;
fp1 = fopen("abc.txt", "r");
fp2 = fopen("xyz.txt", "w");
while((ch = getc(fp1)) != EOF)
putc(ch, fp2);
fclose(fp1);
fclose(fp2);
return 0;
}
OUTPUT:
(none)

Weitere ähnliche Inhalte

Was ist angesagt?

CAMBRIDGE IGCSE COMPUTER SCIENCE
CAMBRIDGE IGCSE COMPUTER SCIENCECAMBRIDGE IGCSE COMPUTER SCIENCE
CAMBRIDGE IGCSE COMPUTER SCIENCE
MohibBasit
 
Teaching Excel
Teaching ExcelTeaching Excel
Teaching Excel
sam ran
 

Was ist angesagt? (20)

Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
C functions
C functionsC functions
C functions
 
Formulas and functions - By Amresh Tiwari
Formulas and functions - By Amresh TiwariFormulas and functions - By Amresh Tiwari
Formulas and functions - By Amresh Tiwari
 
Algorithms and Flowcharts
Algorithms and FlowchartsAlgorithms and Flowcharts
Algorithms and Flowcharts
 
C Structures & Unions
C Structures & UnionsC Structures & Unions
C Structures & Unions
 
C++ Language
C++ LanguageC++ Language
C++ Language
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1
DATABASE MANAGEMENT SYSTEM PRACTICAL LAB ASSIGNMENT 1
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
 
Microsoft excel
Microsoft excelMicrosoft excel
Microsoft excel
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
 
What is Switch Case?
What is Switch Case?What is Switch Case?
What is Switch Case?
 
CAMBRIDGE IGCSE COMPUTER SCIENCE
CAMBRIDGE IGCSE COMPUTER SCIENCECAMBRIDGE IGCSE COMPUTER SCIENCE
CAMBRIDGE IGCSE COMPUTER SCIENCE
 
Type casting in c programming
Type casting in c programmingType casting in c programming
Type casting in c programming
 
11 constructors in derived classes
11 constructors in derived classes11 constructors in derived classes
11 constructors in derived classes
 
Flowchart and algorithem
Flowchart and algorithemFlowchart and algorithem
Flowchart and algorithem
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 
Programming Fundamentals Functions in C and types
Programming Fundamentals  Functions in C  and typesProgramming Fundamentals  Functions in C  and types
Programming Fundamentals Functions in C and types
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Teaching Excel
Teaching ExcelTeaching Excel
Teaching Excel
 

Ähnlich wie Programming in C Lab

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 

Ähnlich wie Programming in C Lab (20)

Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
B.Com 1year Lab programs
B.Com 1year Lab programsB.Com 1year Lab programs
B.Com 1year Lab programs
 
C file
C fileC file
C file
 
C-programs
C-programsC-programs
C-programs
 
C important questions
C important questionsC important questions
C important questions
 
Progr3
Progr3Progr3
Progr3
 
C
CC
C
 
C Programming Lab.pdf
C Programming Lab.pdfC Programming Lab.pdf
C Programming Lab.pdf
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Programming egs
Programming egs Programming egs
Programming egs
 
C code examples
C code examplesC code examples
C code examples
 
Hargun
HargunHargun
Hargun
 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
Najmul
Najmul  Najmul
Najmul
 
All important c programby makhan kumbhkar
All important c programby makhan kumbhkarAll important c programby makhan kumbhkar
All important c programby makhan kumbhkar
 
C programs
C programsC programs
C programs
 
C-LOOP-Session-2.pptx
C-LOOP-Session-2.pptxC-LOOP-Session-2.pptx
C-LOOP-Session-2.pptx
 

Mehr von Neil Mathew

Mehr von Neil Mathew (20)

AMIZONER: Weekly Progress Reports
AMIZONER: Weekly Progress ReportsAMIZONER: Weekly Progress Reports
AMIZONER: Weekly Progress Reports
 
AMIZONER: Final Report
AMIZONER: Final ReportAMIZONER: Final Report
AMIZONER: Final Report
 
Computer Graphics Lab
Computer Graphics LabComputer Graphics Lab
Computer Graphics Lab
 
Role of IT & Computer in Environment
Role of IT & Computer in EnvironmentRole of IT & Computer in Environment
Role of IT & Computer in Environment
 
French Open
French OpenFrench Open
French Open
 
Data Structures Lab
Data Structures LabData Structures Lab
Data Structures Lab
 
DBMS Lab
DBMS LabDBMS Lab
DBMS Lab
 
Communication Assessment File
Communication Assessment FileCommunication Assessment File
Communication Assessment File
 
Cloud Computing and Google's advancement in the field
Cloud Computing and Google's advancement in the fieldCloud Computing and Google's advancement in the field
Cloud Computing and Google's advancement in the field
 
Unix Programming Lab
Unix Programming LabUnix Programming Lab
Unix Programming Lab
 
The Cube - Class XII Project
The Cube - Class XII ProjectThe Cube - Class XII Project
The Cube - Class XII Project
 
Copywriting & Storyboarding (Advertising & Sales Promotion)
Copywriting & Storyboarding (Advertising & Sales Promotion)Copywriting & Storyboarding (Advertising & Sales Promotion)
Copywriting & Storyboarding (Advertising & Sales Promotion)
 
American Airlines Merger (Management In Action Case Study)
American Airlines Merger (Management In Action Case Study)American Airlines Merger (Management In Action Case Study)
American Airlines Merger (Management In Action Case Study)
 
Good Governance Leads To Flourish Society & Nation (BS SAP)
Good Governance Leads To Flourish Society & Nation (BS SAP)Good Governance Leads To Flourish Society & Nation (BS SAP)
Good Governance Leads To Flourish Society & Nation (BS SAP)
 
High Fortune (Product Brand Management)
High Fortune (Product Brand Management)High Fortune (Product Brand Management)
High Fortune (Product Brand Management)
 
Cost Benefit Analysis in Public Project Appraisal (PPAC)
Cost Benefit Analysis in Public Project Appraisal (PPAC)Cost Benefit Analysis in Public Project Appraisal (PPAC)
Cost Benefit Analysis in Public Project Appraisal (PPAC)
 
Corportate Entrepreneurship at WIPRO
Corportate Entrepreneurship at WIPROCorportate Entrepreneurship at WIPRO
Corportate Entrepreneurship at WIPRO
 
Consumer Perception of Job Seekers in updating their Job Profiles on Job Portals
Consumer Perception of Job Seekers in updating their Job Profiles on Job PortalsConsumer Perception of Job Seekers in updating their Job Profiles on Job Portals
Consumer Perception of Job Seekers in updating their Job Profiles on Job Portals
 
How OLX changed the consumer involvement in the Scrap Market
How OLX changed the consumer involvement in the Scrap MarketHow OLX changed the consumer involvement in the Scrap Market
How OLX changed the consumer involvement in the Scrap Market
 
Innovation Jockeys 3 - Gramseva: Kisan
Innovation Jockeys 3 - Gramseva: KisanInnovation Jockeys 3 - Gramseva: Kisan
Innovation Jockeys 3 - Gramseva: Kisan
 

Kürzlich hochgeladen

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Kürzlich hochgeladen (20)

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 

Programming in C Lab

  • 1. 1
  • 2. 2 (Basics) 1. WAP to print text on the screen. 2. WAP to check if number is odd or even. 3. WAP to check which of the two entered numbers is greater. 4. WAP to check whether entered number is a leap year or not. 5. WAP to convert temperature in Fahrenheit to Celsius. (Looping) 6. WAP to display the multiplication table of entered number. 7. WAP to check if number is Palindrome or not. 8. WAP to check if number is an Angstrom number or not. 9. WAP to check if number is a prime or not. 10.WAP to find the sum of Fibonacci series. (Arrays) 11.WAP to find the sum and average of 10 numbers using arrays. 12.WAP to add elements of two 3x3 matrices. (Pointers & Functions) 13.WAP to understand pointers. 14.WAP to swap two numbers. 15.WAP to Swap two numbers using pointers (and functions). 16.WAP to find the factorial of a number using recursive function. (Structures) 17.WAP using structures to input and display details of student. (Strings) 18.WAP to enter two strings and get them to display. (Data File Handling) 19.WAP to enter and retrieve a character from a file. 20.WAP to copy the contents of one file to another. 3 4 5 6 7 8 9 10 11 12 13 14 16 17 18 19 20 21 22 23
  • 3. 3 Write a Program to display text on screen. SOURCE CODE: 1 2 3 4 5 6 7 #include<stdio.h> int main() { printf(" Welcome to Neil's Practical File. XD "); return 0; } OUTPUT: Welcome to Neil's Practical File. XD
  • 4. 4 Write a Program to check if number is odd or even. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> int main() { int num; printf(" Enter the number: "); scanf(" %d ", &num); if(num%2==0) printf("n Number is Even. "); else printf("n Number is Odd. "); return 0; } OUTPUT: Enter the number: 5 Number is Odd. Enter the number: 8 Number is Even.
  • 5. 5 Write a Program to check which of the two entered numbers is greater. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 #include <stdio.h> main () { int a,b,c; printf("n Enter two Numbers: "); scanf("%d%d",&a,&b); c=a ? b:a ; printf("n Greater number of the two is : %d n",c); } OUTPUT: Enter two Numbers: 5 357 Greater number of the two is : 357
  • 6. 6 Write a Program to check whether entered number is a leap year or not. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include <stdio.h> main() { int Y; printf("Enter any year: "); scanf("%d", &Y); if((Y%4==0)) printf("nThe entered year is a Leap Year."); else printf("nThe entered year is not a Leap Year."); return 0; } OUTPUT: Enter any year: 1991 The entered year is not a Leap Year. Enter any year: 1994 The entered year is a Leap Year.
  • 7. 7 Write a Program to convert temperature in Fahrenheit to Celsius. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #include <stdio.h> int main() { float Tf, Tc; printf("Enter temperature in Farenheit: "); scanf("%f", &Tf); Tc=((Tf-32)*(5.0/9.0)); printf("The temperature in Celcius is %f", Tc); return 0; } OUTPUT: Enter temperature in Farenheit: 98.6 The temperature in Celcius is 37.000000
  • 8. 8 Write a Program to display the multiplication table of entered number. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #include<stdio.h> int main() { int i,n,a; printf("nEnter the number whose table is to be printed : "); scanf("%d",&n); for(i=1;i<11;i++) { a=n*i; printf("%dx%i=%d n",n,i,a); } return 0; } OUTPUT: Enter the number whose table is to be printed : 5 5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45 5x10=50
  • 9. 9 Write a Program to check if number is Palindrome or not. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include <stdio.h> main() { int num; //number inputted by user int n; //temporary storage int rev=0; //stores the reverse of that number int digit; //stores the individual digits printf(" Enter the number to check if it's Palindrome or not: "); scanf("%d", &num); n=num; do { digit=n%10; rev=(rev*10)+digit; n=n/10; } while(n>0); if(rev==num) { printf("n The number is a palindrome. "); } else { printf("n The number is not a palindrome. "); } } OUTPUT: Enter the number to check if it's Palindrome or not: 121 The number is a palindrome. Enter the number to check if it's Palindrome or not: 153 The number is not a palindrome.
  • 10. 10 Write a Program to check if number is an Angstrom number or not. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include <stdio.h> main() { int num; //number inputted by user int n; //temporary storage int A=0; //stores the sum of the cube of the digits int digit; //stores the individual digits printf(" Enter the number to check if it's Angstrom or not: "); scanf("%d", &num); n=num; do { digit=n%10; A+=(digit*digit*digit); n=n/10; } while(n>0); if(A==num) { printf("n The number is an Angstrom number. "); } else { printf("n The number is not an Angstrom number. "); } } OUTPUT: Enter the number to check if it's Angstrom or not: 121 The number is not an Angstrom number. Enter the number to check if it's Angstrom or not: 153 The number is an Angstrom number.
  • 11. 11 Write a Program to check if number is a prime or not. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include<stdio.h> int main() { int num; printf("n Enter the number to check whether prime or not: "); scanf(" %d ",&num); if( num==0 || num==1 ) { printf("n The number is not prime. "); } else { int i=0; int flag=1; // 1 if prime, 0 if not prime for(i=2; i<num; i++) { if(num%i==0) { flag=0; break; } } if(flag==1) { printf("n The number is prime. "); } else { printf("n The number is not prime "); } }return 0; } OUTPUT: Enter the number to check whether prime or not: 1 The number is not prime. Enter the number to check whether prime or not: 5 The number is prime. Enter the number to check whether prime or not: 12 The number is not prime.
  • 12. 12 Write a Program to find the sum of Fibonacci series. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 #include<stdio.h> main() { int sum=0; int n; printf("n Till which term should the Fibonacci series be found: "); scanf(" %d ", &n); printf("n The Fibonacci Series: n "); if( n==0 ) { printf(" None "); } else if( n==1 ) { printf("0"); } else { int i,temp; int first=0,second=1; //2nd term printf("%d + %d ",first,second); sum+=second; for(i=3; i<=n; i++) //3rd term onwards { temp=second; second=second+first; first=temp; printf("+ %d ",second); sum+=second; } } printf("n Sum = %d",sum); } OUTPUT: Till which term should the Fibonacci series be found: 8 The Fibonacci Series: 0 + 1 + 1 + 2 + 3 + 5 + 8 + 13 Sum = 33
  • 13. 13 Write a Program to find the sum and average of 10 numbers using arrays. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 #include <stdio.h> int main() { //INITIAL DECLARATIONS int x[10]; int sum=0; float avg; int i; //INPUT printf("n Enter the 10 numbers: n "); for(i=0; i<10; i++) { scanf(" %d ", &x[i]); // *Note the & for array element } //CALCULATIONS for(i=0; i<10; i++) { sum+=x[i]; } avg=sum/10.0; //OUTPUT printf("n The Sum of the numbers: %d ",sum); printf("n The Average of the numbers: %f n",avg); return 0; } OUTPUT: Enter the 10 numbers: 1 2 3 4 5 6 7 8 9 10 The Sum of the numbers: 55 The Average of the numbers: 5.500000
  • 14. 14 Write a Program to add elements of two 3x3 matrices. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #include<stdio.h> int main() { int A[3][3], B[3][3]; int i,j; //INPUT of MATRIX/ 2D ARRAY A printf("n Enter the elements of matrix A: n"); for(i=0; i<3; i++) { for(j=0; j<3; j++) { scanf(" %d ", &A[i][j]); } } //INPUT of MATRIX/ 2D ARRAY B printf("n Enter the elements of matrix B: n"); for(i=0; i<3; i++) { for(j=0; j<3; j++) { scanf(" %d ", &B[i][j]); } } //ADDING THE TWO MATRICES printf("n Adding matrices A and B = matrix C "); int C[3][3]; for(i=0; i<3; i++) { for(j=0; j<3; j++) { C[i][j]=A[i][j]+B[i][j]; } } //OUTPUT printf("n Matrix C is: n"); for(i=0; i<3; i++) { for(j=0; j<3; j++) { printf(" %d ", C[i][j]); } printf("n"); } return 0; }
  • 15. 15 OUTPUT: Enter the elements of matrix A: 1 2 3 1 2 3 3 2 1 Enter the elements of matrix B: 3 2 1 3 2 1 1 2 3 Adding matrices A and B = matrix C Matrix C is: 4 4 4 4 4 4 4 4 4
  • 16. 16 Write a Program to understand pointers. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #include <stdio.h> main() { int a,*p; printf("Enter an integer: "); scanf("%d",&a); p = &a; printf("nAddress of a: %u", &a); printf("nnAddress of p: %u", &p); printf("nnValue of p: %d", p); printf("nnValue of a: %d", a); printf("nnValue of a: %d", *p); } OUTPUT: Enter an integer: 7 Address of a: 3219592736 Address of p: 3219592732 Value of p: -1075374560 Value of a: 7 Value of a: 7
  • 17. 17 Write a Program using structures to input and display details of student. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include <stdio.h> struct student { char name[20]; float marks; int age; }b1, b2; main() { printf("n Enter Names, Marks & Age of the students: n"); scanf("%s %f %d",&b1.name,&b1.marks,&b1.age); scanf("%s %f %d",&b2.name,&b2.marks,&b2.age); printf("n This is what you have entered: n"); printf("n %s %f %d ",b1.name,b1.marks,b1.age); printf("n %s %f %d ",b2.name,b2.marks,b2.age); } OUTPUT: Enter Names, Marks & Age of the students: Neil 94 18 Bugger 0 100 This is what you have entered: Neil 94.000000 18 Bugger 0.000000 100
  • 18. 18 Write a program to swap two numbers. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #include<stdio.h> int main() { int a,b; printf("n Enter the value of A: "); scanf("%d",&a); printf(" Enter the value of B: "); scanf("%d",&b); //Swapping: int temp; temp=a; a=b; b=temp; printf("n After Swapping... n"); printf(" A: %d", a); printf("n B: %d", b); return 0; } OUTPUT Enter the value of A: 5 Enter the value of B: 10 After Swapping... A: 10 B: 5
  • 19. 19 Write a Program to Swap two numbers using pointers. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #include<stdio.h> void Swap(int *a, int *b) { // *Note the syntax of pointers for arguments //Swapping: int temp; temp=*a; // *(pointer_variable) to access the value *a=*b; *b=temp; } int main() { int a,b; printf("n Enter the value of A: "); scanf("%d",&a); printf(" Enter the value of B: "); scanf("%d",&b); Swap(&a,&b); // *Note the & during such a call printf("n After Swapping... n"); printf(" A: %d", a); printf("n B: %d", b); return 0; } OUTPUT: Enter the value of A: 4 Enter the value of B: 9 After Swapping... A: 9 B: 4
  • 20. 20 Write a Program to find the factorial of a number using recursive function. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 #include<stdio.h> int fact(int f) { if( f==1 || f==0) { return 1; } else { f=f*fact(f-1); return f; } } main() { int num; int factorial; printf(" Enter the number whose factorial needs to be found: "); scanf(" %d ", &num); factorial=fact(num); printf("n The factorial of %d is %d. ",num,factorial); } OUTPUT: Enter the number whose factorial needs to be found: 0 The factorial of 0 is 1. Enter the number whose factorial needs to be found: 4 The factorial of 4 is 24.
  • 21. 21 Write a Program to enter two strings and get them to display. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #include <stdio.h> int main() { char S1[20]; char S2[20]; //the datatype string doesn't exist in C. //method 1: can only take one word at a time (till spaces). printf("n Enter the first string: "); scanf(" %s ", S1); //method 2: can take whole line including spaces. printf(" Enter the second string: "); gets(S2); printf("n The Strings are:n 1st: %sn 2nd: ",S1); puts(S2); return 0; } OUTPUT: Enter the first string: Hello Enter the second string: World The Strings are: 1st: Hello 2nd: World Enter the first string: New York Enter the second string: The Strings are: 1st: New 2nd: York
  • 22. 22 Write a Program to enter and retrieve a character from a file using DATA FILE HANDLING. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 #include <stdio.h> main() { char ch; FILE *file; file = fopen("abc.txt", "w"); printf("nEnter any character into FILE: "); scanf("%c", &ch); putc(ch, file); fclose(file); file = fopen("abc.txt", "r"); ch = getc(file); printf("nEntered Character from FILE: %c", ch); } OUTPUT: Enter any character into FILE: Y Entered Character from FILE: Y
  • 23. 23 Write a program to copy the contents of one file to another using DATA FILE HANDLING. SOURCE CODE: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include <stdio.h> main() { char ch; FILE *fp1, *fp2; fp1 = fopen("abc.txt", "r"); fp2 = fopen("xyz.txt", "w"); while((ch = getc(fp1)) != EOF) putc(ch, fp2); fclose(fp1); fclose(fp2); return 0; } OUTPUT: (none)