0% found this document useful (0 votes)
10 views

C File

Uploaded by

Nischay Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

C File

Uploaded by

Nischay Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

BCA 1st Semester DISHA GUPTA (Enrollment No.

03916702023)

PRACTICAL-1
Ques. Write a program to print Hello World.

#include<stdio.h>
int main()
{
prin ("\nHello World");
getch();
}

OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-2
Ques. Write a program to Print Your Own Name.

#include<stdio.h>
int main()
{
char name[20];
prin ("Enter name: ");
scanf("%s",name);
prin ("Your name is %s", name);
getch();
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-3
Ques. Write a program to Print the ASCII Value of a Character.

#include <stdio.h>
void main()
{
char c;
prin ("Enter a character: ");
scanf("%c", &c);
// display the actual integer value of the character
prin ("ASCII value of %c = %d", c, c);
getch();
}

OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-4
Ques. Write a program to convert temperature from Celsius to Fahrenheit by taking input
from the user.

#include <stdio.h>
int main()
{
float celsius, fahrenheit;

/* Input temperature in celsius */


prin ("Enter temperature in Celsius: ");
scanf("%f", &celsius);

/* celsius to fahrenheit conversion formula */


fahrenheit = (celsius * 9 / 5) + 32;
prin ("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit);
getch();
}

OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-5
Ques. Write a program to Find the Size of int, float, double, and char.

#include<stdio.h>
int main()
{
int intType;
float floatType;
double doubleType;
char charType;

// sizeof evaluates the size of a variable


prin ("Size of int: %ld bytes\n", sizeof(intType));
prin ("Size of float: %ld bytes\n", sizeof(floatType));
prin ("Size of double: %ld bytes\n", sizeof(doubleType));
prin ("Size of char: %ld byte\n", sizeof(charType));
getch();
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-6
Ques. Write a program to Swap Two Numbers (Without using third variable).

#include<stdio.h>
int main()
{
int x, y;
//User to input values for x and y
prin ("Input value for x & y: ");
scanf("%d%d",&x,&y);

// Display the values of x and y before swapping


prin ("\nBefore swapping the value of x & y: %d %d",x,y);
x = x + y;
y = x - y;
x = x - y;

// Display the values of x and y a er swapping


prin ("\nA er swapping the value of x & y: %d %d",x,y);
return 0;
}

OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-7
Ques. Write a program to find the greatest number among 3 numbers given by the user.

#include <stdio.h>
int main()
{
int A, B, C;
prin ("Enter the numbers A, B and C: ");
scanf("%d %d %d", &A, &B, &C);
// finding greatest number using compound expressions
if (A >= B && A >= C)
prin ("%d is the largest number.", A);
else if (B >= A && B >= C)
prin ("%d is the largest number.", B);
else
prin ("%d is the largest number.", C);
return 0;
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-8
Ques. Write a program to calculate the Area and Perimeter of Rectangle.

#include <stdio.h>
void main()
{
float l, w, p, a;

/* Taking input of the length of the rectangle from the user */


prin ("\nEnter the length of the Rectangle: ");
scanf("%f", & l);

/* Taking input of the width of the rectangle from the user */


prin ("\nEnter the width of the Rectangle: ");
scanf("%f", & w);

/* Calculate perimeter of the rectangle */


p= 2 * (l + w);
prin ("\nPerimeter of the Rectangle: %0.2f", p);

/* Calculate area of the rectangle */


a = l * w;
prin ("\nArea of the Rectangle: %0.2f", a);
getch();
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-9
Ques. Write a program to Check Whether a Character is Vowel or Consonant.

#include <stdio.h>
int main()
{
char c;
int lowercase_vowel, uppercase_vowel;
prin ("\nEnter 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)
prin ("%c is a vowel.", c);
else
prin ("%c is a consonant.", c);
return 0;
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-10
Ques. Write a program to Calculate Sum of Digits.

#include<stdio.h>
int main()
{
int n,sum=0,m;
prin ("Enter a number: ");
scanf("%d",&n);
while(n>0)
{
m=n%10;
sum=sum+m;
n=n/10;
}
prin ("Sum is=%d",sum);
return 0;
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-11
Ques. Write a program to check if a given number is a prime number or not.

#include <stdio.h>
int main()
{
int num, i, j = 0;
prin ("Enter number: ");
scanf("%d", &num);
for (i = 1; i <= num; i++)
{
if ((num % i) == 0)
{
j++;
}
}
if (j == 2)
prin ("%d is a prime number.", num);
else
prin ("%d is not a prime number.", num);
return 0;
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-12
Ques. Write a program to display the following pa ern upto N rows, taking the value of N
from the user:
1
23
456
7 8 9 10

#include <stdio.h>
int main()
{
int rows, i, j, number = 1;
prin ("\nEnter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= i; ++j)
{
prin ("%d ", number);
++number;
}
prin ("\n");
}
return 0;
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-13
Ques. Write a program to Print Inverted Half Pyramid of Number.
55555
4444
333
22
1

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,rows;
prin ("\nEnter the number of rows:");
scanf("%d",&rows);
for (i=rows;i>=1; i--)
{
for (j=1;j<=i; j++)
{
prin ("%d",i);
}
prin ("\n");
}
getch();
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-14
Ques. Write a program to Print Full Pyramid Pa ern of Numbers.
1
222
33333
4444444
555555555

#include <stdio.h>
int main()
{
int i,j,k,rows;
prin ("\nNumber of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= 2 * (rows - i); j++)
{
prin (" ");
}
for (k = 1; k < 2 * i; k++) {
prin ("%d ", i);
}
prin ("\n");
}
return 0;
}
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-15
Ques. Write a program to input marks of 50 students using an array and display the average
marks of the class.

#include <stdio.h>
int main()
{
int n, i;
float num[100], sum = 0.0, avg;
printf("Enter the number of students: ");
scanf("%d", &n);
while (n > 100 || n < 1)
{
printf("Error! number should in range of (1 to 100).\n");
printf("Enter the number again: ");
scanf("%d", &n);
}
for (i = 0; i < n; ++i)
{
printf("Enter marks of student %d: ", i + 1);
scanf("%f", &num[i]);

sum += num[i];
}
avg = sum / n;
printf("Average = %.2f", avg);
return 0;
}

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-16
Ques. Write a program to search for a number entered by the user in a given array and
display the array in ascending order.

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i,j,s,f=0,t;
clrscr();
printf("\nEnter Value of N (<=10): ");
scanf("%d",&n);
printf("\nEnter Elements: ");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}
}
}
printf("\nAscending Order ");
for(i=0;i<n;i++)
printf("%d ",a[i]);
getch();
}

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-17
Ques. Write a program to check if a string is a palindrome or not.

#include<stdio.h>
#include<conio.h>
void main()
{
char a[10];
clrscr();
int len=0,s,e,m;
printf("\nEnter String: ");
gets(a);
while(a[len]!='\0')
{
len++;
}
s=0; e=len-1;
m=len/2;
for(s=0;s<m;s++)
{
if(a[s]!=a[e])
{
printf("Not Palindrome");
break;
}
else
{
e--;
}
}
if(s==m)
{
printf("Palindrome");
}
getch();
}

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)
OUTPUT

C Language
BCA 1st Semester DISHA GUPTA (Enrollment No. 03916702023)

PRACTICAL-18
Ques. Write a program to add, subtract, multiply and divide two numbers using pointers.

#include<stdio.h>
#include<conio.h>
void main()
{
int n1,n2,*p1,*p2,a,s,m,d;
clrscr();
printf("\nEnter 2 Numbers: ");
scanf("%d %d",&n1,&n2);
p1=&n1;
p2=&n2;
a=*p1+*p2;
printf("\nAdd %d",a);
s=*p1-*p2;
printf("\nSubtract %d",s);
m=*p1**p2;
printf("\nMultiply %d",m);
d=*p1/ *p2;
printf("\nDivide %d",d);
getch();
}
OUTPUT

C Language

You might also like