[go: up one dir, main page]

0% found this document useful (0 votes)
38 views12 pages

Fundamentals of Computer Programming

The document contains 10 programs written in C language to demonstrate basic programming concepts like arithmetic operations, loops, arrays, functions etc. Each program has the objective, code, and sample output. Concepts covered include Hello World, arithmetic, loops, conditional statements, arrays and functions.
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)
38 views12 pages

Fundamentals of Computer Programming

The document contains 10 programs written in C language to demonstrate basic programming concepts like arithmetic operations, loops, arrays, functions etc. Each program has the objective, code, and sample output. Concepts covered include Hello World, arithmetic, loops, conditional statements, arrays and functions.
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/ 12

[Type here]

FUNDAMENTALS OF COMPUTER
PROGRAMMING-LAB
COURSE CODE: DSC-3

SUBMITTED TO: DR.JUHI JAIN


(ASSISTANT PROFESSOR)
SUBMITTED BY: MOHIT KUMAR

SR.NO-71

SEMESTER-1st

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

BRANCH-ECE B3

FACULTY OF TECHNOLOGY , UNIVERSITY OF DELHI

INDEX (BASIC PROGRAM)


SR PROGRAM DATE OF SIGNATURE
NO SUBMISSION
.

1 Hello World Program: Introduction to C programming with a


simple program to print "Hello, World!".

2 Basic Arithmetic Operations: Program to perform basic


arithmetic operations (addition, subtraction, multiplication,
division).

3 Simple Interest Calculation: Calculating simple interest with


given principal, rate, and time.

4 Temperature Conversion: Program to convert temperature


from Celsius to Fahrenheit and vice versa.

5 Sum of Natural Numbers: Calculating the sum of natural


numbers up to a given limit using loops.

6 Check Even or Odd Number: Program to determine if a


number is even or odd using if-else statements.

7 Calculate Factorial using Loops: Finding the factorial of a


number using for loop.

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

8 Basic Array Operations: Program to define, initialize, and


display a 1-D array.

9 Array operations: To find smallest, largest, average, max and


min from list of n numbers.

10 Swap two numbers: using and without using third variable.

Program # 1

Objective : Write a program to print “Hello, World!” .


Program Code :
#include <stdio.h>
int main()
{
printf("Hello, World!");
return 0;
}

Output :

Program # 2
Objective : write a program for basic arithmetic operations (addition, subtraction,
multiplication, division).
Program Code :
#include <stdio.h>
int main() {

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

float a,b,sum,sub,multiply,division;
printf("enter the value of a,b");
scanf("%f%f",&a,&b);
sum = a+b;
sub = a-b;
multiply = a*b;
division = a/b;
printf("the sum is %f\n",sum);
printf("the sub is %f\n",sub );
printf("the multiply is %f\n",multiply );
printf("the divisionis %f\n",division );
return 0;
}
Output :

Program # 3
Objective : Simple Interest Calculation: Calculating simple interest with given
principal, rate, and time.
#include<stdio.h>
int main()
{
float p,r,t,simple_interest;
printf("enter the value of p,r,t");

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

scanf("%f%f%f",&p,&r,&t);
simple_interest = p*r*t/100;
printf("simple_interest is %f",simple_interest);
return 0;
}
Output :

Program # 4
Objective: Temperature Conversion: Program to convert temperature from Celsius
to Fahrenheit and vice versa.
#include <stdio.h>
int main() {
float c ,f;
printf("enter the value of c ");
scanf("%f",&c);
f = (1.8*c)+32;
printf("temp in farenite is %f",f);

return 0;
}
Output :

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

Program # 5
Objective : Sum of Natural Numbers: Calculating the sum of natural numbers up to
a given limit using loops.
#include <stdio.h>
int main() {
int n, i, sum = 0;

printf("Enter a positive integer: ");


scanf("%d", &n);

for (i = 1; i <= n; ++i) {


sum += i ;
}

printf("Sum = %d", sum);


return 0;
}
Output :

Program # 6

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

Objective : Check Even or Odd Number: Program to determine if a number is even


or odd using if-else statements.
#include <stdio.h>
int main() {
int a;
printf ("enter the value of a");
scanf ("%d",&a);
if (a%2==0)

printf("the number is even");

else
printf("the given number is odd");

return 0;
}
Output :

Program # 7
Objective : Calculate Factorial using Loops: Finding the factorial of a number using
for loop.
#include<stdio.h>
int main()
{
int nbr, i, f = 1;
printf("Enter a number to calculate its factorial: ");

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

scanf("%d", &nbr);

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


f = f * i;
printf("%d! = %ld\n", nbr, f);
return 0;
}
Output :

Program # 8
Objective : Basic Array Operations: Program to define, initialize, and display a 1-D
array.
#include <stdio.h>
int main()
{
int arr[5];
for (int i = 0; i < 5; i++) {
arr[i] = i * i - 2 * i + 1;
}
printf("Elements of Array: ");
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}

return 0;
}

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

Output :

Program # 9
Objective : Array operations: To find smallest, largest, average, max and min from
list of n numbers
#include <stdio.h>
int main() {
int n, i;
printf("Enter the number of elements: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements:\n", n);
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
int sum = 0;
int smallest = arr[0];
int largest = arr[0];
for (i = 0; i < n; i++) {
sum += arr[i];
if (arr[i] < smallest) {
smallest = arr[i];
}

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

if (arr[i] > largest) {


largest = arr[i];
}
}

// Calculate average
float average = (float)sum / n;

// Display results
printf("Smallest: %d\n", smallest);
printf("Largest: %d\n", largest);
printf("Average: %.2f\n", average);
printf("Max: %d\n", largest);
printf("Min: %d\n", smallest);

return 0;
}
Output :

Program # 10
Objective : Swap two numbers: using and without using third variable.

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

#include<stdio.h>
int main() {
double a, b, temp;
printf("Enter a: ");
scanf("%lf", &a);
printf("Enter b: ");
scanf("%lf", &b);
temp = a;
a = b;
b = temp;
printf("\nAfter swapping, first numbe = %lf\n",a);
printf("After swapping, second number = %lf\n",b);
return 0;
}
Output :

MOHIT KUMAR ( ECE-B3, SR.NO-71)


[Type here]

MOHIT KUMAR ( ECE-B3, SR.NO-71)

You might also like