0% found this document useful (0 votes)
8 views15 pages

C Language Practicals For Copies

The document contains a series of C programming practicals that cover basic programming concepts such as printing output, taking user input, performing arithmetic operations, and using control structures like loops and conditionals. Each practical includes code snippets that demonstrate specific tasks, such as calculating the area of a triangle, checking for leap years, and generating multiplication tables. The practicals are designed to help learners understand fundamental programming techniques and syntax in C.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views15 pages

C Language Practicals For Copies

The document contains a series of C programming practicals that cover basic programming concepts such as printing output, taking user input, performing arithmetic operations, and using control structures like loops and conditionals. Each practical includes code snippets that demonstrate specific tasks, such as calculating the area of a triangle, checking for leap years, and generating multiplication tables. The practicals are designed to help learners understand fundamental programming techniques and syntax in C.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Practical 1 (Write a program to print your Name and Roll Number on the

Screen)
#include<stdio.h>

#include<conio.h>

void main()

printf("My name is ");

printf("\n My Roll Number is 45212");

Practical 2 (Write a program to print the value of integer and Float)


#include<stdio.h>

#include<conio.h>

void main()

int x=45;

float ft=45.76;

printf("Integer value is %d",x);

printf("\n Float value is %f",ft);

getch();

Practical 3 (Write a program take input of character from user and print ASCII
values on the screen)
#include<stdio.h>

#include<conio.h>

void main()

char c;

printf("Enter a character: ");

scanf("%c",&c);

printf("ASCII value of %c = %d",c,c);


getch();

Practical 4 (Write a program to take input)


#include<stdio.h>

#include<conio.h>

void main()

int a,b, sum;

clrscr();

printf("Enter First integers: ");

scanf("%d",&a);

printf("Enter second integers: ");

scanf("%d",&b);

sum= a+b;

printf("%d + %d = %d ",a,b,sum);

getch();

Practical 5 (Write a program to find the Area and perimeter of Triangle)


#include<stdio.h>

#include<conio.h>

void main()

int a,b,c, p;

float s,A;

clrscr();

printf("Enter The value of Side1 \t");

scanf("%d",&a);

printf("Enter The value of Side2 \t");

scanf("%d",&b);

printf("Enter The value of Side3 \t");

scanf("%d",&c);
s= (a+b+c)/2.0;

A=sqrt(s*(s-a)*(s-b)*(s-c));

P=a+b+c;

printf("Area of triangle is \t %d",P);

getch();

Practical 6 (Write a program to find the centigrade and Fahrenheit temp.)


#include<stdio.h>

#include<conio.h>

void main()

int choice;

float F,C;

clrscr();

printf("Enter 1 to find Fahrenheit temp \t");

scanf("%d",&choice);

if (choice==1)

printf("Enter The value of Centigrade to find Fahrenheit \t");

scanf("%f",&C);

F=9.0/5.0*C+32;

printf("Fahrenheit temp is %f\t",,F);

if (choice==2)

printf("Enter the value of Fahrenheit to find centigrade\t");

scanf("%f",&F);

C=5.0/9.0*(F-32);

printf("Centigrade temp is %f\t",C);

getch();
}

Practical 7 (Write a program to get integer value and print a message if


number is divisible by 3 and 2)
#include<stdio.h>

#include<conio.h>

void main()

int n;

clrscr();

printf("\n Enter the Number: ");

scanf("%d",&n);

if((n%3==0)&& (n%2==0))

printf("\n Its Divisible by 3 and 2");

else

printf("\n Its not Divisible by 3 and 2");

getch();

Practical 8 (Write a program that finds whether a given year is leap or not.
Leap year is a year that is divisible by 4)
#include<stdio.h>

#include<conio.h>

void main()

int y;

clrscr();

printf("Enter Year to check Leap or not:\t");

scanf("%d",&y);
if(y%4==0)

printf("Leap Year");

else

printf("Not Leap Year");

getch();

Practical 9 (Write a program takes character from user and check whether
character is Vowel or Consontant)
#include<stdio.h>

#include<conio.h>

void main()

char ch;

clrscr();

printf("Enter any alphabet");

scanf("%c",&ch);

switch(ch)

case 'a': case 'A':

printf("Vowel");

break;

case 'e': case 'E':

printf("Vowel");

break;

case 'i': case 'I':

printf("Vowel");

break;
case 'o': case 'O':

printf("Vowel");

break;

case 'u': case 'U':

printf("Vowel");

break;

default:

printf("Consontant");

getch();

Practical 10 (write a Program that print (Pass, Fail, or Conditionally Pass) on


the basis of input value.
#include<stdio.h>

#include<conio.h>

void main()

float n;

clrscr();

printf("Enter Percentage of Student in HSC/Inter exam:");

scanf("%f",&n);

if(n>=40 && n<=59)

printf("Conditilly Pass");

else if (n>=60 && n<100)

printf("Pass");

else

printf("Please enter Number from 0-100");

getch();

Practical 11 (write a Program that takes Number from user and check number
is prime or composite using while loop.)
#include<stdio.h>

#include<conio.h>

void main ()

int n, i=1, c=1;

clrscr();

printf("Enter number to Find Prime or not: ");

scanf("%d",&n);

while (i<=n/2)

if (n%i==0)

c=0;

i=i+1;

if (c==2)

printf("The number is Prime");

else

printf("The number is Composite");

getch();

Practical 12 (write a Program that takes Number from user and print the
factorial of only positive number using while loop.)

#include<stdio.h>

#include<conio.h>

void main ()

int n, i=1, fact=1;

clrscr();

printf("Enter Positive Number to Find Factorial");


scanf("%d",&n);

while (i<=n)

fact=fact*i;

i++;

printf("\n Factorial = %d is %d",n,fact);

getch();

Practical 13 (write a Program that takes base and power of number and print
the Result using while loop.)

#include<stdio.h>

#include<conio.h>

void main ()

int base, power, result=1;

clrscr();

printf("Enter a base number: ");

scanf("%d",&base);

printf("Enter a Power number: ");

scanf("%d",&power);

while (power!=0)

result = result*base;

--power;

printf("Answer = %d",result);

getch();

}
Practical 14 (write a Program that takes number from user and print the table
of given Number using do while loop.)

#include<stdio.h>

#include<conio.h>

void main ()

int num,a=1;

clrscr();

printf("Enter a number to print table: \t");

scanf("%d",&num);

do

printf("%d * %d = %d \n",num,a,num*a);

a++;

while (a<=10);

getch();

Practical 15 (write a Program that displays the following output using nested
for loop
1 2 3 4
5 6 7
8 9
10.)

#include<stdio.h>

#include<conio.h>

void main ()
{

int x,y,n;

n=1;

clrscr();

for (x=4; x>=1; x--)

for (y=1; y<=4; y++)

if (y>x)

printf(" ");

else

printf("%d\t",n++);

printf("\n");

getch();

Practical 16 (write a Program that displays the following output using nested
for loop
1 2 3 4
1 2 3
1 2
1.)

#include<stdio.h>

#include<conio.h>

void main ()

int i,j;

clrscr();

for (j=4; j>=1; j--)

{
for (i=1; i<=4-j; i++)

printf(" ");

for (i=1; i<=j; i++)

printf("%4d",i);

printf("\n\n");

getch();

Practical 17 (write a Program that displays the following output using nested
for loop
1
1 2
1 2 3
1 2 3 4.

#include<stdio.h>

#include<conio.h>

void main ()

int i,j;

clrscr();

for (j=1; j<=4; j++)

for (i=1; i<=4-j; i++)

printf(" ");

for (i=1; i<=j; i++)

printf("%4d",i);

printf("\n\n");
}

getch();

Practical 18 (write a Program that displays the following output using nested
for loop
*
**
***
****
*****
#include<stdio.h>
#include<conio.h>
void main ()
{
int r,c;
clrscr();
for (c=1; c<=5; c++)
{
for (r=1; r<=c; r++)
printf("*");
printf("\n");
}
getch();
}
Practical 18 (write a Program that displays the following output using nested
for loop
@ @ @ @
% % % %

& & & &


#include<stdio.h>
#include<conio.h>
void main ()
{
int r,c;
clrscr();
for (c=1; c<=3; c++)
{
for (r=1; r<=c; r++)
if (c==1)
printf("\n@ @ @ @");
if (c==2)
printf("\n% % % %");
if (c==3)
printf("\n& & & &");
}
getch();
}

Practical 19 (write a Program that displays the table of number which is enter
by user using for loop.)
#include<stdio.h>
#include<conio.h>
void main ()
{
int num,i,ans;
clrscr();
printf("Enter a number to generate the table: ");
scanf("%d",&num);
printf("\n Table of %d",num);
for (i=1; i<=10; i++);
{
ans=num*i;
printf("%d * %d = %d",num,i,ans);

Practical 20 (write a Program that displays the Factorial of number which is


enter by user using for loop.)
#include<stdio.h>
#include<conio.h>
void main ()
{
int num,i,fact=1;
clrscr();
printf("Enter a number to generate the Factorial: ");
scanf("%d",&num);
printf("\n Factorial of %d",num);
for (i=1; i<=num; i++);
{
fact=fact*i;

}
printf("Factorial of %d is : %d",num,fact);
}

You might also like