We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 25
PT. J.L.N GOVT. COLLEGE
SEC-16 A, FARIDABAD
PRACTICAL FILE
ON
“PRACTICAL FILE OF C “
‘SUBMITTED TO:
NAME: DR. KALPANA GUPTA
SUBMITTED BY
NAME : KHUSHI TANWAR
CLASS : BCA 2" SEM
CLASS ROLL NO : 120019011009
UNIVERSITY ROLL NO:2[Page
INDEX
S.N CONTECT Page no.
1. | Program to check if given number is Armstrong or not 3-4
2. | Program to check if given number is palindrome or not 5
3. | Program to Find ASCII Value of a Character 6
4, | Program to Calculate the Sum of Natural Numbers 7
5. | Program to Make a Simple Calculator Using switch...case 8-9
6. | Program to Find Factorial of a Number using Recursion. 10
7. | Program to Find Transpose of a Matrix 11-13
8. | Program to Add Two Matrices Arrays 15-17
9. | Program to Find the Length of a String 18
10) Program to Concatenate Two Strings 19-20
11| Program Swap Numbers in Cyclic Order Using Call by 21-22
Reference
12| Program to find greatest of three numbers 23-24
13] Program To Find Sum Of Even And Odd Numbers 25-263 [Page
Program to check if given number is Armstrong or not
include
int main()
{
int number, a, count = 0, result = 0, multiply = 1, ent, remainder;
printf("Please enter a number To check Number is an Armstrong or not:");
scanf("s6d", &number);
a= number;
while (q != 0)
{
a=4/10;
count++;
}
ent = count;
a= number;
while (q != 0)
{
remainder = q % 10;
while (cnt != 0)
{
multiply = multiply * remainder;
ent;
i
result = result + multiply;
ent = count;4[Pace
q=4/ 10;
multiply = 4;
}
if (result == number)
printf("%d is an Armstrong number", number);
printf("%d is not an Armstrong number", number);
Result
Please enter a number To check Number is an Armstrong or not:153
153 is an Armstrong number5|Page
Program to check if given number is palindrome or not
include
int main()
{
int num, reversed = 0, remainder, originalnum;
printf("Enter an integer [ To check number is palindrome or not J:");
scanf("%d", &num);
originalnum = num;
while (num |= 0)
{
remainder = num % 10;
reversed = reversed * 10 + remainder;
num /= 10;
if (originalnum == reversed)
printf("%d is a palindrome.", originalnum);
printf("%d is not a palindrome.", originalnum);
return 0;
1
Result
Enter an integer [ To check number is palindrome or not ]: 12321
12321 is a palindrome.6 [Pace
Program to Find ASCII Value of a Character
Hinclude
void main)
{
char character;
printf("Enter the Character [To find ASCII value] :\n"};
scanf("96c" &character);
printf("ASCII value of %c is %d" character, character);
Result
Enter the Character [To find ASCII value]
A
ASCII value of A is 657[Page
Program to Calculate the Sum of Natural Numbers
#include
void main()
{
int num,i,sum=0;
printf("Enter the the last Natural number :");
scanf("96d!", num);
for (i= 1; 1 <= num; iH)
{
}
printf("Sum of Natural is %d",sum);
Result
Enter the the last Natural number :54
‘Sum of Natural is 1485Program to Make a Simple Calculator Using switch...case
include
void main()
{
float numt, num2, result;
char operator;
printf("Enter [number1] [+ * /] [number2]\n");
scanf("%f %c %f", &inum1, &operator, &num2 );
if (num >= 0 && num1
{
99) | | (num2 >= 0 && num2
switch (operator)
{
case +":
result = num1 + num2;
break;
case“
result = num’ - num2;
break;
case":
result = num1 * num2;
break;
case '/":
result = num1 /num2;
break;9|Page
default:
printf("Error! operator is not correct\n"
}
printf("%.2F 9c %.2F-%.2F", num4, operator, num2,result);
}
else printf("Error! operator is not correct");
Result
Enter [numberi] [+ - * /] [number2]
54+54
54,00 + 54.00--108.00
Enter [number!] [+ - * /] [number2]
45/5
45.00 / 5.00--9.0010] Pace
Program to Find Factorial of a Number using Recursion
Hincludecstdio.h>
int factoriallintn);
void main()
{
int num;
printf("Enter the number to find Factorial :
scanf("%d",&num);
printf("factorial of %d is 9d",num, factorial(num));,
int factorial{int n)
{
if(n==1)
return 1;
else
return n * factorial(n-1);
Result
Enter the number to find Factorial : 5
factorial of 5 is 1201|Page
Program to Find Transpose of a Matrix
include
void main()
{
int N;
printf("Enter number of rows=colunms\n");
scanf("%d",&N);
int matrix1[NJ[N], i,j;
printf("Enter %d*%d matrix value\n",N,N);
for (i
< Nz i+)
{
for (j= 0; j
void main()
{ int;
printf("Enter number of rows=colunms\n");
scanf("%d",&N);
int matrix1[NJ[N], matrix2[N][N], ij;
printf("Enter %d*%d matrix value\n", N,N);
for (i= 0; 1
include
void main()
{
char *string;
printf("Enter the string :\n");
scanf("%s", string);
printf("Lentgh of a string is 9d", strlen(string));
Result
Enter the string
mycomputer
Lentgh of a string is 1019|Page
Program to Concatenate Two Strings
Hinclude
int main()
{
char stringi{S0], string2(50];
int length, i;
printf("Enter first String : \n"
gets(string1 );
printf("Enter second String : \n");
gets(string2};
length = 0;
while (string1[length] != ‘\0')
{
+#length;
tring2{i] !='\0'; ++i, ++length)
string1 [length] = string2[i];
stringi[length] = '\o';
printf("After concatenation: ");20| Pace
puts(string1);
return 0;
Result
Enter first String :
switch
Enter second String :
off
After concatenation:22|Page
Result
Enter ab c respectively
123
Value before swapping:
Value after swapping:
as323|Page
Program to find greatest of three numbers
Hinclude
fidefine N 3
int fun);
int main()
{
inti, a[N];
printf("Enter Three Number [To check Which is greater] :
for (i= 0; 1
fidefine N7
void main()
{
int Size, i, 10];
int EvenSum = 0, OddSum = 0;
printf("\nPlease Enter the 7 numbers [Even and Odd] : \n");
for(i
I< N54)
{
scanf("s6d", &ai));
forli=0;1