C Language
C Language
DATE:
NUMBER OR NOT USINGC
FIND OUT THE GIVEN NUMBER IS PERFECT
PROGRAM
ALGORITHM:
Step 1: Start
End of If Structure]
Compute: I=I+1|
End of While Loop]
Else
Print: N is not a Perfect number.
Step 6: Exit
PROGRAM:
#nclude<stdio.h>
int main()
int n.i=1,sum=0;
whilei<n)i
if(n%i==0)
sum=sumti;
it+;
if(sum=n)
printf"od is a perfect number",i);
else
printf%d is not a perfect number",i);
return 0;
Output:
Enter a number: 6
6 is a perfect number
EXP: 2
DATE:
WRITE A CPROGRAM TOCHECK WHETHERTHE GIVEN NUMBER IS ARMSTRONG
OR NOT
ALGORITHM:
Step 1: Start
Step 5: sum=sum+(reminder*reminder#reminder)
Step 6: number=number/10
Output:
Enter a number: 153
153 is an Armstrong number
http://www.cquestions.com/2008/01/write-c-program-to-tind-pertect-number.html
EXP:3
DATE
WRITE A C PROGRAM TO FIND THE SUM OF
INTEGER INDIVIDUAL DIGITS OF A POSITIVE
ALGORITHM
Step 1: Start
Step 2: Read: Take Input N
Step 3: Initializing SUM] Set: SUM =0
Step 4: Repeat WhileN+0
Set: SUM N%10 -
SUM and
Set: N N/10
End of While Loop]
Step 5: Print: Sum of Digits of N is SUM
Step 6: Exit
PROGRAM
#include <stdio.h>
int sum(int n):
int main)
int num,add;
printf("Enter a positive integer:\n");
scanf"%d",&num);
add=sum(num);
printf("sum=%d".add);
int sum(int n)
if(n==0)
return n
else
return nt+sum(n-1);
Output:
Enter a positive integer: 5
15
DAT
WRUTE AC PROGRAM 1O GENERAIE THE FIRST N TERMs OF THE FIBONNACI
SERIES
ALGORIHM
STEP 1 Start
STEP 7: End
PROGRAM:
#include<stdio.h>
int main(01
int k,r,
long int i=01j=1,f,
for(k=2;k<r;kt+){
f=itj
F
printf(" %ld"j);
returm 0;
Output:
Enter the number range: 15
FIBONACCI SERIES: 0112358 13 21 34 55 89 144 233 377
EXP:6
DATE:
WRITE AC PROGRAM TOGENETARE ALL THE PRIME NUMBERS BETWEEN 1 TO
N. WHERE N IS A VALUE SUPPLIED BY THE USER
ALGORITHM
Step 1: Start
Step 2: Declare variables n.i,flag.
Step 3: Initialize variables
flag-1
i-2
Step 4: Read n from user.
Step 5: Repeat the steps until is(n/2)
5.1 Ifremainder of n*i equals 0
flag-0
Go to step 6
5.2 i-i+1
Step 6: If flag=0
Display n is not prime
else
Display n is prime
Step 7: Stop
PROGRAM:
#includestdio.h
int isPrime(int,int),
int main()
int num,prime:
printf"Enter a positive number: ");
scanf%d",&num),
prime isPrimetnum.num/2);
if(primem1)
printf"od is a prine number",num);
else
printf"od is not a prime number",num);
return 0;:
Output:
Enter a positive number: 13
13 is a prime number
EXP: 7
DATE:
WRITE AC PROGRAM TO FIND THE LARGEST AND SMALLEST NUMBER INA LIST
OF INTEGERS
ALGORITHM:
#include<stdio.h>
#include<conio.h>
void main()
int n,big,sml,i,totalNumber;
clrscr()
printf("n How many number you will enter : ");
scanf(%d",&totalNumber):
for (i-0;istotalNumber;it+)
big=sml=n;
ifbigsn) big=n;
if(sml>n) sml=n;
ALGORITHM
Step1: Start
Step2: Read: m and n
Step3: Read: Take inputs for Matrix A[l:m, l:n) and Matrix B[I:m, l:n]
Step4: Repeat for i =l to m by 1:
Repeat for j :=1 to n by 1:
C[i. j]=A[i, j] + B[i, j]
End of inner for
loopP
|End of outer for loop]
Step5: Print: Matrix C
Step6: Exit
PROGRAM
*Addition of two matrix*
#include<stdio.h>
#includeconio.h>
void main)
int a[3][3].b[3][3].c[3][3]ij.m.n:
clrscr);
printf"Enter the rows and columns:"):
scanf("%d %d".&m.&n):
printf(" nEnter Matrix A values:");
for(i-0:i<m:i++)
forj-0j<nj-)
scanf("%d".&a[i]0]):
getch()
OUT PUT
Entered order as 2, 2 i.e. two rows and two columns and matrices as
First Matrix A:
12
34
Second matrix B:-
45
-15
then output of the program (sum of First and Second matrix) will be
57
29
B.MUL TIPLICATION OF TWOMATRICS
ALGORITHM
Stepl: Start
Step2: Read: m, n. p and q
Step3 Read: Inputs for Matrices A||:m. I:n] and B[l:p,
l:q].
Step4: If n# p then:
Prnt: Multiplication is not possible.
Else:
Repeat tor i I to nm by 1:
Repeat for j I to q by I:
Cli.j0 [Initializingl
Repeat k: Ito n byI
Ci.jl=Ci.il A[i. k] x B[k. 3]
+
*Matrix Multiplication*/
#include<stdio.h>
#include<conio.h>
void main( )
int a[25][25].b[25][25].c[25][|25],.ij.k.r,s,m,n;
clrscr( );
printf("Enter the number of rows and columns of matrix A");
scanf("%d%d",&m,&n);
printf("Enter the number of rows and columns of matrix B")
scanf("%d%d",&r,&s);
if(n!=r)
printf("The matrix cannot be multiplied");
else
getch( );
Output:
Enter the number rows and columns of the first matrix
33
120
011
201
Enter the number rows and columns of the second matrix
33
1 12
211
121
Product of entered matrix:
534
3 32
34 5
EXP: 9
DATE:
Write a program to perform various string operations.
ALGORITHM:
Step 1: start
Step 5: if X! =0
else
strepy ($3,S1)
Ll strlenS1)
L2 strlen($2)
L3= strlen ($3)
Step 6: Stop
PROGRAM:
#include <stdio.h>
#include<conio.h>
#include<string.h>
#includectype.h>
#include<stdlib.h>
void main() {
char a 100], b[100];
int result, option,
do
printf("nl.Length of a string");
printf("n2.Reverse the Given String");
printf("n3.Check for Palindrome");
printf("in4.Copy");
printf("n5.String Comparison");
printf"n6.String Concatenation");
printf"n7.String Searching");
printf("n8.Counting of Words,Characters & Special Characters"):
printf("n9.Quit");
printf("in\nEnter Your Choice:");
scanf("%d", &option);
flushall):
switch (option)
case 1
printf("inEnter a String:");
gets(a);
result = length(a);
case 5:
printf("nEnter 1st string:");
gets(a);
printf("nEnter 2nd string:");
gets(b);
result=compare(a,b);
if(result== 0)
printf("inboth are same");
else if (result > 0)
printf("inlst>2nd");
else
printf("nlst<2nd");
printf("nPress a Character");
getch():
break;
case 6:
printf(" nEnter Ist string:");
gets(a):
printf(" nEnter 2nd string:");
gets(b);
concat(a, b);
printf("inresult=%s", a);
printf("nPress a Character");
getch();
break;
case 7:
printf(" nEnter Ist string:");
gets(a);
printf"inEnter 2nd string:");
gets(b);
search(a, b
printf("inPress a Character");
getch();
break;
case 8:
printf(" nEnter a string:");
gets(a);
count(a);
printf("nPress a Character");
getch();
break;
default:
printf("inlnvalid Choice:");
break;
i++
J-
return (00);
i++
J-
return ();
str2[i] = "0';
str1[i] = \0';