Rohan Kumar C Practical PDF
Rohan Kumar C Practical PDF
PRACTICAL - 01
Introduction to C language
C is a procedural programming language initially developed by Dennis Ritchie in the year
1972 at Bell Laboratories of AT&T Labs. It was mainly developed as a system programming
language to write the UNIX operating system.
These features make the C language suitable for system programmings like an operating
system or compiler development.
Many later languages have borrowed syntax/features directly or indirectly from the C
language. Like syntax of Java, PHP, JavaScript, and many other languages are mainly based
on the C language. C++ is nearly a superset of C language (Only a few programs may
compile in C, but not in C++).
So, if a person learns C programming first, it will help him to learn any modern
programming language as well. As learning C help to understand a lot of the underlying
architecture of the operating system. Like pointers, working with memory locations, etc.
Installing Visual Studio Code
https://code.visualstudio.com/
13.Click Finish to exit Setup. Check in the check box to launch VS Code right now.
17.All done!
PROGRAM
#include <stdio.h>
int main() {
printf("Hello World!");
return 0;
}
OUTPUT
PROGRAM
#include <stdio.h>
int main() {
float a,b,c;
printf("enter first number\n");
scanf("%f",&a);
printf("enter second number\n");
scanf("%f",&b);
printf("enter third number\n");
scanf("%f",&c);
printf("sum of three numbers = %f\n",a+b+c);
return 0;
}
OUTPUT
PROGRAM
#include <stdio.h>
int main() {
char c;
printf("Enter a character :");
scanf("%c", &c);
printf("ASCII value of %c = %d \n", c, c);
return 0;
}
OUTPUT
PROGRAM
#include <stdio.h>
int main() {
int p,t;
float r;
printf("enter principle amount:");
scanf("%d",&p);
printf("enter rate of interest:");
scanf("%f",&r);
printf("enter time period:");
scanf("%d",&t);
printf("simple interest is: %f\n",(p*r*t)/100);
return 0;
}
OUTPUT
PROGRAM
#include <stdio.h>
int main() {
char ch;
printf("enter a character:");
ch=getchar();
printf("The character entered is:");
putchar(ch);
return 0;
}
OUTPUT
PROGRAM
#include <stdio.h>
#include <string.h>
int main() {
char name[15];
printf("enter name:");
gets(name);
printf("The name entered is:");
puts(name);
return 0;
}
OUTPUT
PROGRAM
#include<stdio.h>
int main() {
float a,b,c,d,e;
printf("enter marks of science:");
scanf("%f",&a);
printf("enter marks of history:");
scanf("%f",&b);
printf("enter marks of computer:");
scanf("%f",&c);
printf("enter marks of maths:");
scanf("%f",&d);
e=(a+b+c+d)/4;
printf("student aggregate marks = %f\n",e);
if(e>=33)
{
printf("student passed\n");
}
else
{
printf("student failed\n");
}
return 0;
}
OUTPUT
Avg=(sub1+sub2+sub3+
sub4)/4
yes
Avg>=40
No
Display ‘’PASS’’
Display ‘’FAIL’’
END
PRACTICAL – 8(ii)
PROGRAM
#include <stdio.h>
int main() {
float l,b;
printf("Enter length of rectangle:");
scanf("%f",&l);
printf("Enter breadth of rectangle:");
scanf("%f",&b);
printf("area of rectangle is = %f ",l*b);
return 0;
}
OUTPUT
Input, Length,
Breadth
Print Area
END
PRACTICAL –09
PROGRAM
#include <stdio.h>
int main() {
float a,b,c;
printf("Enter First number:");
scanf("%f",&a);
printf("Enter Second number:");
scanf("%f",&b);
printf("Enter Third number:");
scanf("%f",&c);
if(a>b && a>c)
{
printf("Maximun number is %f",a);
}
else if(b>a && b>c)
{
printf("Maximun number is %f",b);
}
else if(c>b && c>a)
{
printf("Maximun number is %f",c);
}
else
{
printf("input error");
}
return 0;
}
OUTPUT
AIM : Write a program to take the marks of a student and display fail if
marks is less than 40% otherwise display The Student is PASS.
PROGRAM
#include<stdio.h>
int main() {
float marks;
printf("enter the marks(%) of a student:");
scanf("%f",&marks);
if(marks<40)
{
printf("The Student is FAIL");
}
else
{
printf("The Student is PASS");
}
return 0;
}
OUTPUT
PROGRAM
#include <stdio.h>
int main() {
int day;
printf("Enter Day Number (like monday =1 to sunday =7)\n");
scanf("%d", &day);
switch(day){
case 1 : printf("Monday\n");
break;
case 2 : printf("Tuesday\n");
break;
case 3 : printf("Wednesday\n");
break;
case 4 : printf("Thursday\n");
break;
case 5 : printf("Friday\n");
break;
case 6 : printf("Saturday\n");
break;
case 7 : printf("Sunday\n");
break;
default: printf("wrong input!\n");
}
return 0;
}
OUTPUT
PROGRAM
#include<stdio.h>
int main() {
int a;
printf("enter any number:");
scanf("%d",&a);
if(a%2 == 0)
{
printf("The number is Even");
}
else
{
printf("The number is odd");
}
return 0;
}
OUTPUT
#include <stdio.h>
int main()
{
int unit;
float amt, total_amt, sur_charge;
return 0;
}
OUTPUT
PRACTICAL –14
PROGRAM :
#include <stdio.h>
int main()
{
int num, c;
printf("enter the number:");
scanf("%d", &num);
for (int i = 1; i <= num; i++)
{
if (num % i == 0)
{
c++;
}
}
if (c == 2)
{
printf("the enter number is a prime number\n");
}
else
{
printf(" enter number is not a prime number\n");
}
return 0;
}
OUTPUT :
PROGRAM :
#include <stdio.h>
int main(){
int a;
for(a=1;a<=10;a++){
printf("%d\n", a);
}
return 0;
}
OUTPUT :
PROGRAM
#include <stdio.h>
int main()
{
int i, n;
return 0;
}
OUTPUT
PRACTICAL –17
PROGRAM
#include <stdio.h>
int main() {
while (n != 0) {
remainder = n % 10;
reverse = reverse * 10 + remainder;
n /= 10;
}
return 0;
}
OUTPUT
PRACTICAL –18
PROGRAM
#include <stdio.h>
int main() {
int n, reversed = 0, remainder, original;
printf("Enter an integer: ");
scanf("%d", &n);
original = n;
return 0;
}
OUTPUT
PRACTICAL –19
PROGRAM- by recursion
#include <stdio.h>
int factorial(int a);
int main()
{
int a;
printf("enter the value\n ");
scanf("%d", &a);
printf("the value of factorial %d is %d\n", a, factorial(a));
return 0;
}
int factorial(int a)
{
printf("the calling value is %d\n", a);
if (a == 1 || a == 0)
{
return 1;
}
else
{
return a * factorial(a - 1);
}
}
OUTPUT
PRACTICAL –19
int main()
{
int num;
printf("enter the number\n");
scanf("%d", &num);
int res = 1, i;
for (i = 2; i <= num; i++)
{
res *= i;
}
OUTPUT
PRACTICAL –20
PROGRAM
#include <stdio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows\n");
scanf("%d", &rows);
OUTPUT
PRACTICAL –21
PROGRAM
#include <stdio.h>
int main()
{
int a[4], i ;
printf("\n Enter the Array Element : \n") ;
for ( i=0 ; i<=4; i++)
{
scanf("%d", &a[i]);
}
printf("\n Array Elements are : \n ") ;
for ( i=0 ; i<=4 ; i++)
{
printf("\t %d ",a[i]) ;
}
return 0;
}
OUTPUT
PRACTICAL –22
PROGRAM
#include <stdio.h>
int main()
{
int num, i, j, array1[50], array2[50];
printf("Enter no of elements in array\n");
scanf("%d", &num);
OUTPUT
PRACTICAL –23
PROGRAM
#include <stdio.h>
int main()
{
int array[100], maximum, size, c, location = 1;
maximum = array[0];
OUTPUT
PRACTICAL –24
PROGRAM
#include<stdio.h>
int main() {
int i, j, a[3][3];
return 0;
}
OUTPUT
PRACTICAL –25
PROGRAM
#include<stdio.h>
int main()
{
int i,j,m,n;
float a[10][10], sum=0.0;
printf("a[%d][%d]=",i,j);
scanf("%f", &a[i][j]);}
}
for(i=0;i< m;i++){
for(j=0;j< n;j++){
sum = sum + a[i][j];}
}
printf("Sum = %f\n", sum);
return 0;
}
OUTPUT
PRACTICAL –26
AIM :Write a program to find the transpose of the element a
matrix.
PROGRAM
#include <stdio.h>
int main() {
int a[10][10], transpose[10][10], r, c;
printf("Enter rows and columns: ");
scanf("%d %d", &r, &c);
PROGRAM
#include<stdio.h>
int main()
{
int i,j,k;
float a[3][3], b[3][3], mul[3][3];
for(i=0;i< 3;i++)
{
for(j=0;j< 3;j++)
{
mul[i][j] = 0;
for(k=0;k< 3;k++)
{
mul[i][j] = mul[i][j] + a[i][k]*b[j][k];
}
}
}