student notes / est. for the classroom

HTML, CSS, JavaScript, Python, data science, computer networks — written the way you'd explain it to a classmate, not a compiler.

Top Job & Internship Portals

Handpicked portals for fresher jobs, tech roles, and listings in Hyderabad

GFG

GeeksforGeeks

Tech & Software Roles

Visit →
INT

Internshala

Fresher Jobs & Internships

Visit →
GOOG

Google Careers

Global Google Openings

Visit →
APN

Apna Jobs

Local Jobs in Hyderabad

Visit →
INS

Instahyre

Tech Roles in Hyderabad

Visit →
NAUK

Naukri.com

Fresher Jobs in Hyderabad

Visit →
📢 Updated daily

Internship & Job Alerts

01

Latest notes

January 05, 2023

PPS Lab Programs

 

Lab 1



C Program to Find Sum and Average of 3 Numbers
#include <stdio.h>
int main(){
int a, b, c, sum;
float avg;
// Asking for input
printf("Enter 3 numbers: \n");
scanf("%d %d %d", &a, &b, &c);
// Calculating sum
sum = a + b + c;
// Calculating average of 3 numbers
avg = sum / 3;
// Displaying output
printf("Sum = %d \n", sum);
printf("Average = %.2f", avg);
return 0;
} Lab 2

Let's see the fibonacci series program in c without recursion.

  1. #include<stdio.h>    
  2. int main()    
  3. {    
  4.  int n1=0,n2=1,n3,i,number;    
  5.  printf("Enter the number of elements:");    
  6.  scanf("%d",&number);    
  7.  printf("\n%d %d",n1,n2);//printing 0 and 1    
  8.  for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed    
  9.  {    
  10.   n3=n1+n2;    
  11.   printf(" %d",n3);    
  12.   n1=n2;    
  13.   n2=n3;    
  14.  }  
  15.   return 0;  
  16.  }    
Lab 3
Program or code for prime numbers between 1 to n in c language

#include<stdio.h>

int main(){

    int num,i,count,n;
    printf("Enter max range: ");
    scanf("%d",&n);

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

         count = 0;

         for(i=2;i<=num/2;i++){
             if(num%i==0){
                 count++;
                 break;
             }
        }
        
         if(count==0 && num!= 1)
             printf("%d ",num);
    }
  
   return 0;
}

Sample output:
Enter max range: 50
2 3 5 7 11 13
Lab 4 Check weather the given number is armstrong or not
#include <stdio.h>
int main() {
    int num, originalNum, remainder, result = 0;
    printf("Enter a three-digit integer: ");
    scanf("%d", &num);
    originalNum = num;

    while (originalNum != 0) {
       // remainder contains the last digit
        remainder = originalNum % 10;
        
       result += remainder * remainder * remainder;
        
       // removing last digit from the orignal number
       originalNum /= 10;
    }

    if (result == num)
        printf("%d is an Armstrong number.", num);
    else
        printf("%d is not an Armstrong number.", num);

    return 0;
}
Lab 5

C Program for Arithmetic Operations using Switch Statement

#include<stdio.h> #include<conio.h> int main() { int a,b; int op; printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n"); printf("Enter the values of a & b: "); scanf("%d %d",&a,&b); printf("Enter your Choice : "); scanf("%d",&op); switch(op) { case 1 : printf("Sum of %d and %d is : %d",a,b,a+b); break; case 2 : printf("Difference of %d and %d is : %d",a,b,a-b); break; case 3 : printf("Multiplication of %d and %d is : %d",a,b,a*b); break; case 4 : printf("Division of Two Numbers is %d : ",a/b); break; default : printf(" Enter Your Correct Choice."); break; } return 0; } Lab 6

Factorial of a Number Using Recursion

#include<stdio.h>
long int multiplyNumbers(int n);
int main() {
    int n;
    printf("Enter a positive integer: ");
    scanf("%d",&n);
    printf("Factorial of %d = %ld", n, multiplyNumbers(n));
    return 0;
}

long int multiplyNumbers(int n) {
    if (n>=1)
        return n*multiplyNumbers(n-1);
    else
        return 1;
}
Lab 7

Program to Add Two Matrices

#include <stdio.h>
int main() {
  int r, c, a[100][100], b[100][100], sum[100][100], i, j;
  printf("Enter the number of rows (between 1 and 100): ");
  scanf("%d", &r);
  printf("Enter the number of columns (between 1 and 100): ");
  scanf("%d", &c);

  printf("\nEnter elements of 1st matrix:\n");
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      printf("Enter element a%d%d: ", i + 1, j + 1);
      scanf("%d", &a[i][j]);
    }

  printf("Enter elements of 2nd matrix:\n");
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      printf("Enter element b%d%d: ", i + 1, j + 1);
      scanf("%d", &b[i][j]);
    }

  // adding two matrices
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      sum[i][j] = a[i][j] + b[i][j];
    }

  // printing the result
  printf("\nSum of two matrices: \n");
  for (i = 0; i < r; ++i)
    for (j = 0; j < c; ++j) {
      printf("%d   ", sum[i][j]);
      if (j == c - 1) {
        printf("\n\n");
      }
    }

  return 0;
}
Lab 8 Sum of digits in c
  1. #include<stdio.h>  
  2.  int main()    
  3. {    
  4. int n,sum=0,m;    
  5. printf("Enter a number:");    
  6. scanf("%d",&n);    
  7. while(n>0)    
  8. {    
  9. m=n%10;    
  10. sum=sum+m;    
  11. n=n/10;    
  12. }    
  13. printf("Sum is=%d",sum);    
  14. return 0;  
  15. }   
Lab 9
  1. /*C program to check whether the given number is the Perfect number*/  
  2. #include<stdio.h>  
  3. #include<conio.h>  
  4. void main()  
  5. {  
  6. // declare and initialize the variables  
  7. int num, rem, sum = 0, i;  
  8. // take an input from the user.  
  9. printf("Enter a number\n");  
  10. scanf("%d", &num);      
  11. // find all divisors and add them  
  12. for(i = 1; i < num; i++)  
  13.                      {  
  14.                               rem = num % i;  
  15.                              if (rem == 0)  
  16.                                         {  
  17.                                                sum = sum + i;  
  18.                                          }  
  19.                         }  
  20. if (sum == num)  
  21.                       printf(" %d is a Perfect Number");  
  22.            else  
  23.                       printf("\n %d is not a Perfect Number");  
  24. getch();  
  25. }  



Lab 10
  • Program to check whether the number is strong or not.
  1. #include <stdio.h>  
  2. int main()  
  3. {  
  4.     int n;  
  5.     int sum=0;  
  6.     printf("Enter a number");  
  7.     scanf("%d",&n);  
  8.     int k=n;  
  9.     int r;  
  10.     while(k!=0)  
  11.     {  
  12.         r=k%10;  
  13.         int f=fact(r);  
  14.         k=k/10;  
  15.         sum=sum+f;  
  16.     }  
  17.     if(sum==n)  
  18.     {  
  19.         printf("\nNumber is a strong");  
  20.     }  
  21.     else  
  22.     {  
  23.         printf("\nNumber is not a strong");  
  24.     }  
  25.     return 0;  
  26. }  
  27. int fact(int r)  
  28. {  
  29.     int mul=1;  
  30.     for(int i=1;i<=r;i++)  
  31.     {  
  32.         mul=mul*i;  
  33.     }  
  34.     return mul;  
  35.       
  36. }  




Lab 11

Program to Find Roots of a Quadratic Equation


#include <math.h>
#include <stdio.h>
int main() {
    double a, b, c, discriminant, root1, root2, realPart, imagPart;
    printf("Enter coefficients a, b and c: ");
    scanf("%lf %lf %lf", &a, &b, &c);

    discriminant = b * b - 4 * a * c;

    // condition for real and different roots
    if (discriminant > 0) {
        root1 = (-b + sqrt(discriminant)) / (2 * a);
        root2 = (-b - sqrt(discriminant)) / (2 * a);
        printf("root1 = %.2lf and root2 = %.2lf", root1, root2);
    }

    // condition for real and equal roots
    else if (discriminant == 0) {
        root1 = root2 = -b / (2 * a);
        printf("root1 = root2 = %.2lf;", root1);
    }

    // if roots are not real
    else {
        realPart = -b / (2 * a);
        imagPart = sqrt(-discriminant) / (2 * a);
        printf("root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", realPart, imagPart, realPart, imagPart);
    }

    return 0;
}



Lab 12

GCD of Two Numbers using Recursion

#include <stdio.h>
int hcf(int n1, int n2);
int main() {
    int n1, n2;
    printf("Enter two positive integers: ");
    scanf("%d %d", &n1, &n2);
    printf("G.C.D of %d and %d is %d.", n1, n2, hcf(n1, n2));
    return 0;
}

int hcf(int n1, int n2) {
    if (n2 != 0)
        return hcf(n2, n1 % n2);
    else
        return n1;
}
Lab 12 find the greatest common divisor (GCD) for the given two numbers
 by using the non-recursive function
#include<stdio.h>
#include<conio.h>
#include<math.h>
int gcdnonR(int i,int j){
   int rem;
   rem=i-(i/j*j);
   if(rem==0)
      return j;
   else
      gcdnonR(j,rem);
}
void main(){
   int a,b;
   printf("enter the two numbers:");
   scanf("%d%d",&a,&b);
   printf("GCD of %d",gcdnonR(a,b));
   getch();
}

No comments:

Post a Comment

02

Capstone resource hub

Codingacharya

Capstone Learning Resources, Notes & Project Hub

TCS NQT Questions
Read Notes
Machine Learning – ACE Theory
Read Notes
Machine Learning PPT
Read Notes
MachienLearning LAB
Read Notes
CSPT LAB programs
Read Notes
Time table and CSPT syllabus
Read Notes
Appreciations
Read Notes
ISTE life memberships
Read Notes
Artificial Intelligence & Analytics
Read Notes
Fullstack Web Dev
Read Notes
MERN Web Dev
Read Notes
Course Structure
Read Notes
Cloud Computing
Read Notes
90 Days ML Challenge
Read Notes
Advanced Analytics & Viz
Read Notes
Advanced Machine Learning
Read Notes
React JS
Read Notes
ML Chaitanya
Read Notes
Important Links
Read Notes
CSS Effects
Read Notes
RESUME
Read Notes
Bootstrap CSS
Read Notes
MongoDB
Read Notes
OWN Python Package
Read Notes
HTML Course
Read Notes
HTML Projects
Read Notes
GitHub Projects
Read Notes
Angular JS
Read Notes
Journals
Read Notes
NLP Notes
Read Notes
Videos
Read Notes
Data Analytics & Viz
Read Notes
Cloud Computing (Archive)
Read Notes
Open CV
Read Notes
jQuery
Read Notes
React JS (Archive)
Read Notes
Node JS
Read Notes
DAV Theory
Read Notes
DAV Lab
Read Notes
Big Data Notes
Read Notes
R-Programming
Read Notes
HADOOP Lab
Read Notes
GATE DA
Read Notes
JAVA Lab
Read Notes
Computer Networks
Read Notes
03

Live projects & profiles