0% found this document useful (0 votes)
86 views47 pages

Vinayak Siddha College: Project Report On

Uploaded by

bishnu paudel
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)
86 views47 pages

Vinayak Siddha College: Project Report On

Uploaded by

bishnu paudel
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/ 47

Vinayak Siddha College

Project Report on
“C-Programming”
Of
“Computer Science”

Under the supervision of


[BashantaKhanal]

Submitted by:
Priya Raut
(Symbol No. - 8011286)

Submitted to:
Bashanta Khanal
Department of Computer Science
Vinayak Siddha College
Chabahil, Kathmandu
2023

1
ACKNOWLEDGEMENT
We owe our deepest gratitude to the Vinayak Siddha College for providing us with an
opportunity to work on a project as part of our syllabus. We are heartily indebted to our Project
Supervisor and Lecturer of Computer Science, Mr. Bashanta Khanal for his constant support and
guidance throughout this project. It was his valuable suggestions that helped us to cope up with
the emerging obstacles during the development of this project.

We are grateful for the initial guidance in our project which motivated us to put more effort in this
project. We are also grateful to all our teachers for their suggestions and inspirational lectures that
paved the way towards the completion of this project.

Also, we would like to thank our friends and colleagues for their valuable comments and
suggestions during this project. Any kind of suggestion will be highly appreciated and
acknowledged.

Thank You!

Priya Raut
Symbol No: 8011286

2
CERTIFICATION

This is to certify that this Project Report on “C-Programming” prepared by [Priya Raut] was
found to satisfy the requirement for the award of Intermediate Level in Computer Science.

------------------------------------
Project Supervisor
Bashanta Khanal
Department of Computer Science
Vinayak Siddha College

3
Table of Contents

4
1. WAP to display the number from 40 to 1 using loop.
#include<stdio.h>
int main()
{
inti;
for(i = 40; i>= 1; i--)
{
printf("%d ", i);
}
return 0;
}

OUTPUT

5
2. WAP to find whether number is odd or even.
#include <stdio.h>
int main()
{
intnum;
printf("Enter an number: ");
scanf("%d", &num);
if(num % 2 == 0)
{
printf("%d is even.", num);
}
else
{
printf("%d is odd.", num);
}
return 0;
}

OUTPUT

6
3. WAP to find the smallest number between two numbers.
#include <stdio.h>
int main()
{
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
if (num1 < num2)
{
printf("%d is the smallest number.", num1);
} else
{
printf("%d is the smallest number.", num2);
}
return 0;
}

OUTPUT

7
4. WAP to find the largest number among three numbers.
#include <stdio.h>
int main()
{
int num1, num2, num3;
printf("Enter three numbers: ");
scanf("%d %d %d", &num1, &num2, &num3);
if (num1 >= num2 && num1 >= num3)
{
printf("%d is the largest number.", num1);
}
else if (num2 >= num1 && num2 >= num3)
{
printf("%d is the largest number.", num2);
}
else
{
printf("%d is the largest number.", num3);
}
return 0;
}

OUTPUT

8
5. WAP to find the number is positive, negative or zero.
#include <stdio.h>
int main()
{
intnum;
printf("Enter a number: ");
scanf("%d", &num);
if (num> 0)
{
printf("The number is positive.");
}
else if (num< 0)
{
printf("The number is negative.");
}
else
{
printf("The number is zero.");
}
return 0;
}

OUTPUT

9
6. WAP to find the name of days depending upon the number entered by user
using switch case.
#include<stdio.h>
int main()
{
int choice;
printf("Enter the number:\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("It is Sunday");
break;
case2:
printf("It is Monday");
break;
case3:
printf("It is Tuesday");
break;
case 4:
printf("It is Wednesday");
break;
case5:
printf("It is Thursday");
break;
case 6:
printf("It is Friday");
break;
case 7:
printf("It is Saturday");
break;
default:
printf(":invalid entry");
break;
}
return 0;
}

10
OUTPUT

7. WAP to calculate the result of student having 5 subjects. Calculate, total


marks, percentage and display the grade according to percentage obtained.
#include<stdio.h>
int main()
{
intenglish, nepali, computer, economics, maths;
float Total, Average, Percentage;
char Grade;
printf("Enter the marks of five subjects:\n");
scanf("%d %d %d %d %d",&english,&nepali, &computer, &economics, &maths);
Total=english+nepali+computer+economics+maths;
Average=Total/5;
Percentage=(Total/5)*100;
printf("Total Marks:%d\n",Total);
printf("Percentage:%f\n",Percentage);
if(Percentage>=90)
{
printf("Grade:A\n");
}
else if(Percentage>=80)
{
printf("Grade:B\n");
}
else if(Percentage>=70)
{
printf("Grade: C\n");

11
}
else if(Percentage>=60)
{
printf("Grade: D\n");
}
else
{
printf("Grade: F\n");
}
return 0;
}

8. WAP to print even number from 2 to 50 using loop.

#include <stdio.h>
int main()
{
inti;
for(i = 2; i<= 50; i += 2)
{
printf("%d ", i);
}
return 0;
}
OUTPUT

12
9. WAP to calculate the multiplication of table of 5 using for loop.
#include <stdio.h>
int main()
{
intnum = 5;
inti;
printf("Multiplication Table of %d:\n", num);
for(i = 1; i<= 10; i++)
{
printf("%d x %d = %d\n", num, i, num * i);
}
return 0;
}

OUTPUT

13
10. WAP to find factorial of a given number.
#include <stdio.h>
int main()
{
intn,i,f=1;
printf("Enter a number: ");
scanf("%d", &n);
for (inti = 1; i<= n; i++)
{
f= f*i;
}
printf("The factorial of %d is %d.\n", n, f);
return 0;
}

OUTPUT

14
11. WAP to find whether the given number is prime or not.
#include <stdio.h>
int main()
{
int n, i, count = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
if (n == 0 || n == 1)
count = 1;
for (i = 2; i<= n / 2; ++i) {
if (n % i == 0)
{
count++;
}
}
if (count == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
return 0;
}

OUTPUT

15
12. WAP to calculate the Fibonacci series upto 20th term.
#include <stdio.h>
int main()
{
int n, first = 0, second = 1, next, i;
printf("Enter the number of terms: ");
scanf("%d", &n);
printf("Fibonacci Series: ");
for (i = 0; i< n; i++)
{
if (i<= 1)
next = i;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d ", next);
}
return 0;
}

OUTPUT

16
13. WAP to calculate the reverse of a number.
#include <stdio.h>
int main()
{
int number, reverse = 0, remainder;
printf("Enter a number: ");
scanf("%d", &number);
while (number != 0)
{
remainder = number % 10;
reverse = reverse * 10 + remainder;
number /= 10;
}
printf("The reverse of the number is: %d", reverse);
return 0;
}

OUTPUT

17
14. WAP to check whether the given number is palindrome or not.
#include <stdio.h>
int main()
{
intnum, reversedNum = 0, remainder, originalNum;
printf("Enter an integer: ");
scanf("%d", &num);
originalNum = num;
while (num != 0)
{
remainder = num % 10;
reversedNum = reversedNum * 10 + remainder;
num /= 10;
}
if (originalNum == reversedNum)
{
printf("%d is a palindrome.", originalNum);
}
else
{
printf("%d is not a palindrome.", originalNum);
}
return 0;
}

OUTPUT

18
15. WAP to find sum of n natural number using for loop.
#include <stdio.h>
int main()
{
int n, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for(inti = 1; i<= n; i++)
{
sum += i;
}
printf("The sum of first %d natural numbers is %d.", n, sum);
return 0;
}

OUTPUT

19
16. WAP to print square of 1 to 100 using loop
#include <stdio.h>
int main()
{
inti;
for(i = 1; i<= 100; i++)
{
printf("The square of %d is %d\n", i, i * i);
}
return 0;
}

OUTPUT

20
17. WAP to print following patterns in C:
*****
****
***
**
*
#include<stdio.h>
int main()
{
inti,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}

21
return 0;
}

OUTPUT

5
55
555
5555
55555
#include<stdio.h>
int main()
{
inti,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("5");
}
printf("\n");

22
}
return 0;
}

OUTPUT

1
12
123
1234
12345
#include<stdio.h>
int main()
{
inti,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

23
OUTPUT

55555
4444
333
22
1
#include<stdio.h>
int main()
{
inti,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
return 0;
}

24
OUTPUT

18. WAP to input 5 numbers in array and display them properly.


#include <stdio.h>
int main()
{
int numbers[5];
printf("Enter 5 numbers:\n");
for (inti = 0; i< 5; i++)
{
printf("Enter number %d: ", i + 1);
scanf("%d", &numbers[i]);
}
printf("\nThe numbers you entered are:\n");
for (inti = 0; i< 5; i++)
{
printf("%d ", numbers[i]);
}
printf("\n");

25
return 0;
}
OUTPUT

19. WAP to input an salary of 40 staffs and calculate the total salary and their
average using array.
#include <stdio.h>
int main()
{
float salaries[40];
floattotalSalary = 0.0;
floataverageSalary;
printf("Enter the salaries of 40 staff members:\n");
for (inti = 0; i< 40; i++)
{
printf("Enter salary for staff %d: ", i + 1);
scanf("%f", &salaries[i]);

26
totalSalary += salaries[i];
}
averageSalary = totalSalary / 40;
printf("\nThe total salary of 40 staff members is: %.2f\n", totalSalary);
printf("The average salary of 40 staff members is: %.2f\n", averageSalary);
return 0;
}
OUTPUT

27
20. WAP to calculate the total number of staffs having salary between
Rs,30,000 and Rs.50,000.
#include <stdio.h>
int main()
{
float salaries[10];
int count = 0;
printf("Enter the salaries of 10 staff members:\n");
for (inti = 0; i< 10; i++) {
printf("Enter salary for staff %d: ", i + 1);
scanf("%f", &salaries[i]);
}
for (inti = 0; i< 10; i++) {
if (salaries[i] >= 30000 && salaries[i] <= 50000) {
count++;
}
}
printf("\nThe total number of staff members with salary between Rs.30,000 and Rs.50,000 is:
%d\n",
count);
return 0;
}

OUTPUT

28
21. WAP to input 10 numbers in array and sort them in ascending order.
#include <stdio.h>
int main()
{
int a[10], i, j, temp;
printf ("Enter any 10 number");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for (i=0;i<10;i++)
{
for (j=0;j<10;j++)
{
if (a[j]>a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
printf("ascending orderd is");
for (i=0;i<10;i++)
{
printf("%d\t",a[i]);
}
return 0;
}
OUTPUT

29
22. WAP to calculate the greatest number among 10 numbers using array.
#include <stdio.h>
int main() {
int numbers[10];
int greatest;
printf("Enter 10 numbers:\n");
for (inti = 0; i< 10; i++)
{
printf("Number %d: ", i + 1);
scanf("%d", &numbers[i]);
}
greatest = numbers[0];
for (inti = 1; i< 10; i++) {
if (numbers[i] > greatest) {
greatest = numbers[i];
}
}
printf("\nThe greatest number among the 10 numbers is: %d\n", greatest);
return 0;
}

OUTPUT

30
23. WAP to input elements 3*3 matrices and perform their sum.
#include <stdio.h>
int main()
{
int a[3][3],b[3][3],c[3][3],i,j;
printf("Enter the value of matrix a:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The matrix a is :\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Enter the value of matrix b:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("The matrix b is :\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("The Subtraction of Matrix a & b is:\n");
for(i=0;i<3;i++)
{

31
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n");
}
return 0;
}

OUTPUT

32
24. WAP to perform the matrix subtraction of 2*2 matrices.
#include <stdio.h>
int main()
{
int a[2][2],b[2][2],c[2][2],i,j;
printf("Enter the value of matrix a:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The matrix a is :\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Enter the value of matrix b:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("The matrix b is :\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("The Subtraction of Matrix a & b is:\n");
for(i=0;i<2;i++)
{

33
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf("%d\t",c[i][j]);
}
printf("\n");
}
return 0;
}

OUTPUT

34
25. WAP to input 3*2 matrix and calculate its transpose.
#include <stdio.h>
int main()
{
int matrix[3][2];
int transpose[2][3];
printf("Enter elements of the 3x2 matrix:\n");
for (inti = 0; i< 3; i++)
{
for (int j = 0; j < 2; j++)
{
printf("Enter element at position (%d, %d): ", i + 1, j + 1);
scanf("%d", &matrix[i][j]);
}
}
for (inti = 0; i< 3; i++)
{
for (int j = 0; j < 2; j++)
{
transpose[j][i] = matrix[i][j];
}
}
printf("\nOriginal Matrix:\n");
for (inti = 0; i< 3; i++)
{
for (int j = 0; j < 2; j++) {
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
printf("\nTranspose of the Matrix:\n");
for (inti = 0; i< 2; i++) {
for (int j = 0; j < 3; j++) {
printf("%d\t", transpose[i][j]);
}
printf("\n");
}
return 0;
}

35
OUTPUT

26. WAP to calculate multiplication of two matrices.


#include <stdio.h>
int main()
{
int a[2][2],b[2][2],c[2][2],i,j,k;
printf("Enter the value of matrix a:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The matrix a is :\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)

36
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Enter the value of matrix b:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("The matrix b is :\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
printf("The multiplication of Matrix a & b is:\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=0;
for(k=0;k<2;k++)
{
c[i][j] =c[i][j]+a[i][k]+b[k][j];

37
}
;
printf("%d\t",c[i][j]);
}
printf("\n");
}
return 0;
}

OUTPUT

38
27. WAP to input five strings and display them.
#include<stdio.h>
int main()
{
char strings[5][100];
for(inti=0;i<5;i++)
{
printf("Enter string %d:",i);
scanf("%s",strings[i]);
}
return 0;
}

28. WAP to demonstrate the example of string function :


a) strlen
#include <stdio.h>
#include <string.h>
int main()
{
char a[10];
int l;
printf("Enter any string:\n");
scanf("%s",a);
l=strlen(a);
printf("The length is %d",l);
return 0;
}

39
OUTPUT

b) strcat
#include <stdio.h>
#include <string.h>e
int main()
{
char a[10],b[10];
printf("Enter first string");
scanf("%s",a);
printf("Enter second string");
scanf("%s",b);
strcat(a,b);
printf("the string is %s\n",a);
return 0;
}

40
OUTPUT

c) strcpy
#include <stdio.h>
#include <string.h>e
int main()
{
char a[10],b[10];
printf("Enter any string 1:\n");
scanf("%s",a);
printf("enterthe string 2:\n");
scanf("%s",b);
strcpy(a,b);
printf("the string is %s\n",a);
return 0;
}

41
OUTPUT

d) strlwr
#include <stdio.h>
#include <string.h>e
int main()
{
char a[10];
printf("Enter any string");
scanf("%s",a);
strlwr(a);
printf("%s",a);
return 0;
}

42
OUTPUT

e) strupr
#include <string.h>
int main()
{
char a[10];
printf("Enter any string");
scanf("%s",a);
strupr(a);
printf("%s",a);
return 0;
}

43
OUTPUT

29. WAP to display the reverse of a string.


#include <stdio.h>
#include <string.h>e
int main()
{
char a[10];
printf("Enter any string");
scanf("%s",a);
strrev(a);
printf("%s",a);
return 0;
}

44
OUTPUT

30. WAP to check whether the given string is palindrome or not.


#include<stdio.h>
#include<string.h>
int main()
{
charstr[20],str1[20];
int c;
printf("enter a string");
gets(str);
strcpy(str1,str);
strrev(str1);
c=strcmp(str,str1);
if(c==0)
printf("string is palindrome");
else

45
printf("string is not paindrome");
return 0;
}

OUTPUT

46
Conclusion
C has enjoyed a long and fruitful life, and it still influences language design today.
Ultimately C++ was created by adding objects to C, and Java was created by cleaning up C++’s
syntax and making it so that it could run on any computer after being compiled once. Therefore,
C tends to look primitive to modern students.

The creators of C++ and Java would quite rightly argue that the process was at least a little more
complicated than this.

Nevertheless, there is still call for C programmers today. A lot of behind the-scenes code for
Python modules is still written in C, as is much of the code for modern operating systems.
Understanding C is also a good first step toward understanding assembly language, since it
translates more directly to assembly without as many intermediate steps. And many computer
games are still written in C or C++, for the speed they can offer.

In short, you may use C every day in your coding career, or you may never use it at all. But there
are undeniable benefits to understanding how the language works, especially as you explore the
inner workings of your computer.

47

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy