1-6 programs

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Class: I B.

Sc (AI& DS)
Computer Programming Lab

1. Write a C program to find the sum, average, standard deviation for a given set
of Numbers.
2. Write a C program to generate n prime numbers.

3. Write a C program to generate Fibonacci series.

4. Write a C program to sort the given set of numbers in ascending


order.

5. Write a C program to count the number of Vowels in the given


sentence.

6. Write a C++ Program to create class, which consists of EMPLOYEE Detail


like E_ Number, E_ Name, Department, Basic, Salary, Grade. Write a member
function to get and display them.
7.writeC++Program to create class SHAPE which consists of two virtual
functions
8.WriteaC++Program using function overloading to read two matrices of
different

DataTypes Such as integers and floating point numbers.

9.Write a C++ Program to create a File and to display the contents of that file
with line numbers.

10.Write a C++ Program to merge two files into a single file.


1. C Program to find the sum, average,standard deviation
************************************

1. #include<stdio.h>
2. #include<math.h>
3.
4. void stand_devi(int, int, int, int, int,
5. float*, float*, float*);
6.
7. int main()
8. {
9. int a, b, c, d, e;
10. float sum = 0, avg = 0, sd = 0;
11.
12. printf("Enter 5 numbers\n");
13. scanf("%d%d%d%d%d", &a, &b, &c, &d, &e);
14.
15. stand_devi(a, b, c, d, e, &sum, &avg, &sd);
16.
17. printf("\nSum = %0.2f\n", sum);
18. printf("Mean / Average = %0.2f\n", avg);
19. printf("Standard Deviation = %0.2f\n", sd);
20.
21. return 0;
22. }
23.
24. void stand_devi(int a, int b, int c, int d, int e,
25. float *sum, float *avg, float *sd)
26. {
27. float v = 0; // Variance
28.
29. *sum = a + b + c + d + e;
30. *avg = *sum / 5.0;
31.
32. v += pow( (a - *avg), 2 );
33. v += pow( (b - *avg), 2 );
34. v += pow( (c - *avg), 2 );
35. v += pow( (d - *avg), 2 );
36. v += pow( (e - *avg), 2 );
37.
38. v /= 5.0;
39.
40. *sd = sqrt(v);
41. }
OUTPUT
********
Enter 5 numbers
50
69
92
30
-60

Sum = 181.00
Mean / Average = 36.20
Standard Deviation = 52.29

2. C Program for Prime numbers


**********************************************
#include <stdio.h>

main() {
int n, i, c = 0;
printf("Enter any number n:");
scanf("%d", &n);

//logic
for (i = 1; i <= n; i++) {
if (n % i == 0) {
c++;
}
}

if (c == 2) {
printf("n is a Prime number");
}
else {
printf("n is not a Prime number");
}
return 0;
}

OUTPUT
********
Enter any number n: 7

n is Prime
3. C program for Fibonacci Series
*********************************

#include<stdio.h>
#include<conio.h>
void main()
{
inta,b,c,i,n;
a=-1,b=1;
clrscr();
printf("Fibonacci\n");
printf("*********\n");
printf("Enter the n:");
scanf("%d",&n);
printf("Fibonacci Series\n");
for(i=0;i<=n;i++)
{
c=a+b;
printf("%d\n",c);
a=b;
b=c;
}
getch();
}
OUTPUT
******** Fibonacci
*********
Enter the n:5
Fibonacci Series
0
1
1
2
3
5
4. C programs for Ascending Order
***************************
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i,j,n,t;
clrscr();
printf("Ascending Order\n");
printf("***************\n");
printf("Enter the value of n:");
scanf("%d",&n);
printf("Enter the %d Number's:\n",n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]>a[j])
{
t=a[i];
a[i]=a[j];
a[j]=t;
}}}
printf("\n Ascending Order is:");
for(i=0;i<n;i++)
{
printf("\n%d",a[i]);
}
getch();
}
OUTPUT
********
Ascending Order
***************
Enter the value of n:5
Enter the 5 Number's:
65783
Ascending Order is:
3
5
6
7
8
5. C program for identify vowels
***************************
#include <stdio.h>
#include <math.h>
#include <string.h>
void Solve()
{
unsigned short count = 0, vowels = 0;
char str[100], c;
printf("Enter a string in which you want to find number of vowels: ");
scanf("%[^\n]", str);
while(str[count] != '\0')
{
c = str[count];
if(c == 'a' || c == 'A' || c == 'e' || c == 'E' || c == 'i' || c == 'I'
|| c == 'o' || c == 'O' || c == 'u' || c == 'U') {
vowels++;
printf("%c", c);
}
count++;
}
printf("\n");
printf("NUMBER OF VOWELS In Given string Are: %hu \n", vowels);
}
int main()
{
Solve();
return 0;
}
Output
Enter a string in which you want to find number of vowels: HELLO
NUMBER OF VOWELS In Given string Are:2
6. C++ program for Employee details
***************************

#include <iostream>
using namespace std;
class employee
{
int emp_number;
char emp_name[20];
float emp_basic;
float emp_da;
float emp_it;
float emp_net_sal;
public:
void get_emp_details();
float find_net_salary(float basic, float da, float it);
void show_emp_details();
};
void employee :: get_emp_details()
{
cout<<"\nEnter employee number: ";
cin>>emp_number;
cout<<"\nEnter employee name: ";
cin>>emp_name;
cout<<"\nEnter employee basic: ";
cin>>emp_basic;
cout<<"\nEnter employee DA: ";
cin>>emp_da;
cout<<"\nEnter employee IT: ";
cin>>emp_it;
}
float employee :: find_net_salary(float basic, float da, float it)
{
return (basic+da)-it;
}
void employee :: show_emp_details()
{
cout<<"\n\n**** Details of Employee ****";
cout<<"\nEmployee Name : "<<emp_name;
cout<<"\nEmployee number : "<<emp_number;
cout<<"\nBasic salary : "<<emp_basic;
cout<<"\nEmployee DA : "<<emp_da;
cout<<"\nIncome Tax : "<<emp_it;
cout<<"\nNet Salary : "<<find_net_salary(emp_basic, emp_da, emp_it);
cout<<"\n-------------------------------\n\n";
}
int main()
{
employee emp;
emp.get_emp_details();
emp.show_emp_details();
return 0;
}

OUTPUT

You might also like