[go: up one dir, main page]

0% found this document useful (0 votes)
114 views28 pages

Output:: Program 1

The document contains 10 programs related to C programming. Program 1 converts height from centimeters to inches and feet. Program 2 checks if a number is an Armstrong number. Program 3 calculates the average of 5 subjects and determines the grade. Program 4 solves quadratic equations. Program 5 prints the Fibonacci series. Program 6 calculates the sine value. Program 8 prints a pattern of increasing characters. Program 9 finds prime factors of a number. Program 10 demonstrates string operations without string library. Program 16 multiplies two matrices.

Uploaded by

srenath
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)
114 views28 pages

Output:: Program 1

The document contains 10 programs related to C programming. Program 1 converts height from centimeters to inches and feet. Program 2 checks if a number is an Armstrong number. Program 3 calculates the average of 5 subjects and determines the grade. Program 4 solves quadratic equations. Program 5 prints the Fibonacci series. Program 6 calculates the sine value. Program 8 prints a pattern of increasing characters. Program 9 finds prime factors of a number. Program 10 demonstrates string operations without string library. Program 16 multiplies two matrices.

Uploaded by

srenath
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/ 28

PROGRAM 1:

#include<iostream.h>
#include<conio.h>
void main ()
{
floatheight,feet,inch;
clrscr();
cout<<"Enter Your Height In Centimeter :";
cin>>height;
inch=0.3937*height;
cout<<"\n"<<"The Height In Inch Is :"<<inch;
feet=inches/12;
cout<<"\n"<<"The In Feet Is :"<<feet;
getch();
}

Output:
Enter Your Height In Centimeter :10
The Height In Inch Is : 3.937
The In Feet Is : 0.3280
PROGRAM 2:
#include<iostream.h>
#include<conio.h>
void main()
{
intn,r,s,sum=0;
clrscr();
cout<<"Enter The Number :";
cin>>n;
s=n;

while(n!=0)
{
r=n%10;
sum=sum*r*r*r;
n=n/10;
}
if(n==sum)
cout<<"The Number Is A Amstrong Number";
else
cout<<"The Number Is Not A Amstrong Number";
getch();
}

Output:
Enter The Number : 153
The Number Is AAmstrong Number.
PROGRAM 3:
#include<iostream.h>
#include<conio.h>
void main()
{
inta,b,c,d,e,sum,avg;
clrscr();
cout<<"Enter Marks Of Any Five Subjects:";
cin>>a>>b>>c>>d>>e;
sum=a+b+c+d+e;
avg=sum/5;
cout<<"The Average Of Five Marks Is:"<<avg<<"\n";
if(avg>=90)
cout<<"The Grade Is A";
else if(avg>=80)
cout<<"The Grade Is B";
else if(avg>=70)
cout<<"The Grade Is C";
else if(avg>=60)
cout<<"The Grade Is D";
else
cout<<"The Grade Is E";
getch();
}

Output:
Enter Marks Of Any Five Subjects : 100 100 100 100 100
The Average Of Five MarksIs : 100
PROGRAM 4:

#include<iostream.h>

#include<conio.h>

#include<math.h>

void main()

{int a,b,c,d,r1,r2,temp,choice;

clrscr();

cout<<"Enter the co-efficients :";

cin>>a>>b>>c;

d=pow(b,2)-4*a*c;

temp=2*a;

cout<<"The value of discriment is:"<<d<<"\n";

if(d==0) choice=0;

else if(d>=1) choice=1;

else choice=2;

switch(choice)

case 0:

cout<<"The roots are real and equal\n";

r1=r2=-1*b/temp;

cout<<"The roots are:"<<r1<<","<<r2;

break;

case 1:

cout<<"The roots are equal and unreal\n";

r1=(-1*b+d)/temp;

r2=(-1*b-d)/temp;

cout<<"The roots are:"<<r1<<","<<r2;

break;

default:

cout<<"The roots are imaginary";

break;

getch();

Output:
Enter the co-efficients : 2 3 4

The Value Of DiscrimentIs : -23

The Roots Are Imaginary.


PROGRAM 5:

#include <iostream.h>

#include <conio.h>

void main()

clrscr();

int n, n1 = 0, n2 = 1, n3 = 0;

cout<< "Enter the number of terms: ";

cin>> n;

cout<< "Fibonacci Series: ";

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

// Prints the first two terms.

if(i == 1)

cout<< n1 << " ";

continue;

if(i == 2)

cout<< n2 << " ";

continue;

n3= n1 + n2;

n1 = n2;

n2 = n3;

cout<< n3 << " ";

getch();

Output:
Enter the number of terms : 5

Fibonacci Series : 0 1 1 2 3.
PROGRAM 6:
#include<iostream.h>
#include<iomanip.h>
#include<conio.h>
//x-x3/3!+x5/5!-x7/7!+....
void main()
{
inti, n;
float x, sum, t;
clrscr();
cout<<" Enter the value for x : ";
cin>>x;
cout<<" Enter the value for n : ";
cin>>n;
x=x*3.14159/180;
t=x;
sum=x;
/* Loop to calculate the value of Sine */
for(i=1;i<=n;i++)
{
t=(t*(-1)*x*x)/(2*i*(2*i+1));
sum=sum+t;
}
cout<<" The value of Sin("<<x<<") = "<<setprecision(4)<<sum;
getch();
}

Output :
Enter The Value For x : 2
Enter The Value For n : 3
The Value Of Sin(0.034907)=0.0349
PROGRAM 8:
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n;
char ch1 ='C',ch;
cout<< "Enter number of rows: ";
cin>> n;
for(inti = n; i>= 1; i--)
{
ch=ch1;
for(int j = 1; j <= i; j=j+1)
{
cout<<ch<<" ";
ch+=2;
}
cout<< "\n";
ch1 = ch1+1;;
}
getch();
}

Output :
Enter number of rows:3
CEG
DF
E
PROGRAM 9:
# include <iostream.h>
# include <conio.h>
void main()
{
int n, i;
clrscr();
cout<< " Enter Any Number : ";
cin>> n;
i = 1;
while(i<= n )
{
if( n % i == 0 )
{
int j = 1, k = 0;
while( j <= i)
{
if(i % j == 0 )
k++;
j++;
}
if( k == 2 )
cout<<i<< " Is A Prime Factor Of " << n;
cout<< "\n";
}
i++;
}
getch();
}

Output :
Enter Any Number :81
3 Is A Prime Factor Of 81
PROGRAM 10:
///fundamental string operation, length, concatenation, compare and copy strings
without string.h
#include<stdio.h>
#include<stdlib.h>
intfind_length(char string[]){
intlen = 0,i;
for(i = 0; string[i]!='\0'; i++){
len++;
}
returnlen;
}
voidjoin_strings(char string1[], char string2[]){
inti, len1, len2;
len1 = find_length(string1);
len2 = find_length(string2);
for(i = len1; i< len1+len2; i++){
string1[i] = string2[i-len1];
}
string1[i] = '\0'; //adding null character at the end of input
}
/*returns 0 if thery are same otherwise returns 1*/
intcompare_strings(char string1[], char string2[]){
int len1, len2, i, count = 0;
len1 = find_length(string1);
len2 = find_length(string2);
if(len1!=len2)
return 1;
for(i = 0; i< len1; i++){
if(string1[i] == string2[i])
count++;
}
if(count == len1)
return 0;
return 1;
}
voidcopy_string(char destination[], char source[]){
intlen,i;
len = find_length(source);
for(i = 0; i<len; i++){
destination[i] = source[i];
}
destination[i] = '\0';
}
int main(){
char string1[20], string2[20]; //string variables declaration with size 20
int choice;
while(1){
printf("\n1. Find Length \n2. Concatenate \n3. Compare \n4. Copy \n5. Exit\n");
printf("Enter your choice: ");
scanf("%d",&choice);
switch(choice){
case 1:
printf("Enter the string: ");
scanf("%s",string1);
printf("The length of string is %d", find_length(string1));
break;
case 2:
printf("Enter two strings: ");
scanf("%s%s",string1,string2);
join_strings(string1,string2);
printf("The concatenated string is %s", string1);
break;
case 3:
printf("Enter two strings: ");
scanf("%s%s",string1,string2);
if(compare_strings(string1,string2)==0){
printf("They are equal");
}else{
printf("They are not equal");
}
break;
case 4:
printf("Enter a string: ");
scanf("%s",string1);
printf("String1 = %s\n");
printf("After copying string1 to string 2\n");
copy_string(string2,string1);
printf("String2 = %s",string2);
break;
case 5:
exit(0);
}
}
return 0;
}
PROGRAM 11:
#include<iostream.h>
#include<string.h>
#include<conio.h>
void main()
{
charstr[65];
int n;
voidnword(char[],int);
clrscr();
cout<<"Enter a string:"<<endl;
cin.getline(str,65);
cout<<"Enter no.of characters to be displayed:";
cin>>n;
nword(str,n);
getch();
}
voidnword(char str[],int n)
{
inti,j,k;
char str2[65];
for(i=0,j=0;str[i]!='\0',j<n;i++,j++)
{
{
str2[j]=str[i];
cout<<str2[j];
}
}}
PROGRAM 12:
#include<iostream.h>
#include<conio.h>
void large(int1 a[],int n)
{
intl,sl;
l=a[0];
sl=a[0];
for(inti=0;i<n;i++)
{
if(a[i]>l)
{
sl=l;
l=a[i];
}
}
cout<<"The Largest Is:"<<l<<endl<<"Second Largest Number Is:"<<sl;
}
void large(int a[],int n);
void main()
{
clrscr();
intarr[20],n1;
cout<<"Enter The No.Of Elements:"<<endl;
cin>>n1;
cout<<"Enter The Element:"<<endl;
for(inti=0;i<n1;i++)
cin>>arr[i];
large(arr,n1);
getch();
}
PROGRAM 13:
#include<iostream.h>
#include<string.h>
#include<conio.h>
#include<stdio.h>
void main()
{ clrscr();
int a1[20],b1[20];
char p1;
void place(int[],int[],int,int,char);
int n2,n3;
cout<<"Enter the no. of elements of the array : ";
cin>>n2;
cout<<"Enter the no. of elements to be moved :";
cin>>n3;
cout<<"1.Enter the first array elements :- ";
for(inti=0;i<n2;i++)
cin>>a1[i];

cout<<"2.Enter the second array elements :- ";


for(int j=0;j<n2;j++)
cin>>b1[j];

cout<<"Elements to added in the beggining 'B' or ending 'E' ...?";


cin>> p1;
place(a1,b1,n2,n3,p1);

getch() ;
}
void place(int a[20],int b[20],intn,int n1,char p)
{
inti,j,k;
if(p=='b'||p=='B')
{
for(i=0,j=0;i<n1;i++,j++)
{
b[j]=a[i];
}
}
else
{
for(i=0,j=n-1;i<n1;i++,j--)
{
b[j]=a[i];
}
}
for(k=0;k<n;k++)
{
cout<<b[k]<<" ";
}
}
PROGRAM 16:

#include<iostream.h>
#include<process.h>
#include<conio.h>
void main()
{
clrscr();
int a[20][20],b[20][20],c[10][10],m1,n1,n2,m2,k,i,j;
void multiply(int a[20][20],int ,int ,int b[20][20],int ,int);
cout<<"\n enter the rows and columns of matrix A:";
cin>>m1>>n1;
cout<<"\n enter the rows and columns of matrix B:";
cin>>n2>>m2;
if(n1==n2)
{
cout<<"\n enter the elements of matrix A:\n";
for(i=0;i<m1;++i)
{
for(j=0;j<n1;++j)
cin>>a[i][j];
}
cout<<"\n enter the elements of matrix B:\n";
for(i=0;i<n2;++i)
{
for(j=0;j<m2;++j)
cin>>b[i][j];
}
cout<<"\n matrix A is:";
for(i=0;i<m1;++i)
{
cout<<"\n";
for(j=0;j<n1;++j)
cout<<a[i][j]<<" ";
}
cout<<"\n matrix B is:";
for(i=0;i<n2;++i)
{
cout<<endl;
for(j=0;j<m2;++j)
cout<<b[i][j]<<" ";
}
}
else
{
cout<<"\n matrix are not compatible for maltiplication.";
}
multiply(a,m1,n1,b,m2,n2);
getch();
}
void multiply(int a[20][20],int m1,int n1,int b[20][20],int m2,int n2)
{
int c[20][20];
int i,j,k;
cout<<"\n product of two matrix:";
for(i=0;i<m1;++i)
{
cout<<"\n";
for(j=0;j<m2;++j)
{
c[i][j]=0;
for(k=0;k<n1;++k)
{ c[i][j]=c[i][j]+a[i][k]*b[k][j];

}
cout<<c[i][j]<<" ";
}
}
}
PROGRAM 17:
#include<iostream.h>
#include<conio.h>
void end(int a[20][20],int m,int n)
{
cout<<"The Elements Ending With 5:"<<endl;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(a[i][j]%10==5)
cout<<a[i][j]<<endl;
}
}
}
void diag(int a[20][20],int m,int n)
{
cout<<"Sum Of The Diognal Element:";
int s=0;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
if(i==j||i+j==m-1)
s=s+a[i][j];
}
}
cout<<s<<endl;
}
void main()
{
int m,n,a[20][20];
clrscr();
cout<<"Enter the values of m and n:";
cin>>m>>n;
cout<<"Enter the value:";
for(int i=0;i<m;i++)
{

for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
end(a,m,n);
diag(a,m,n);
getch();
}
PROGRAM 18:

#include<iostream.h>
#include<conio.h>
void transpose(int a[20][20],int m,int n)
{
cout<<"The transpose matrix is:"<<endl;
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
cout<<a[j][i]<<" ";
}
cout<<endl;
}
}
void sumoddrow(int a[20][20],int m,int n)
{
for(int i=0;i<m;i++)
{
for(int j=0,s=0;j<n;j++)
{
if(i%2!=0)
{
s+=a[i][j];
}
}
cout<<"The sum of the value in row "<<i+1<<" is:"<<s<<endl;
}
}
void main()
{
int i,j,m,n,a[20][20];
clrscr();
cout<<"Enter the value of m:";
cin>>m;
cout<<"Enter the value of n:";
cin>>n;
cout<<"Enter the elements of the matrix:";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>a[i][j];
}
}
transpose(a,m,n);
sumoddrow(a,m,n);
getch();
}
PROGRAM 14
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int arr[20],brr[20],n1;
void create2d(int[],int[],int);
cout<<"Enter the maximum number of elements:";
cin>>n1;
cout<<"Enter the values for the first array\n";
for(int i=0;i<n1;i++)
cin>>arr[i];
cout<<"Enter the values for the second array\n";
for(int j=0;j<n1;j++)
cin>>brr[j];
create2d(arr,brr,n1);
getch();
}
void create2d(int a[20],int b[20],int n){
int c[20][20];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
c[i][j] = a[i] * b[j];
}
}
cout<<"The following is the 2-d array created from 1-d array\n";
for(int l=0;l<n;l++){
for(int m=0;m<n;m++){
cout<<c[l][m]<<" ";
}
cout<<"\n";
} }
PROGRAM 15
#include<iostream.h>
#include<conio.h>
void main(){
clrscr();
int arr[20],brr[20],n1;
void create2d(int[],int[],int);
cout<<"Enter the maximum number of elements:";
cin>>n1;
cout<<"Enter the values for the first array\n";
for(int i=0;i<n1;i++)
cin>>arr[i];
cout<<"Enter the values for the second array\n";
for(int j=0;j<n1;j++)
cin>>brr[j];
create2d(arr,brr,n1);
getch();
}
void create2d(int a[20],int b[20],int n){
int c[20][20];
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
c[i][j] = a[i] * b[j];
}
}
cout<<"The following is the 2-d array created from 1-d array\n";
for(int l=0;l<n;l++){
for(int m=0;m<n;m++){
cout<<c[l][m]<<" ";
}
cout<<"\n";
} }
PROGRAM:19
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
struct donor{
int DonorNo;
char DonorName[10];
char Bloodgroup[11];
};
void main(){
clrscr();
int n,i,j,flag;
donor d[20];
char bgroup[14];
strcpy(bgroup,"O Negative");
if(strcmp(bgroup,"O Negative"))
cout<<"inside if";
cout<<"Enter the total number of Donors:: ";
cin>>n;

i=0;
do{
cout<<endl<<"Enter Donor Number : ";
cin>>d[i].DonorNo;

cout<<"Enter Donor Name : " ;


gets(d[i].DonorName);

cout<<"Enter Donor Blood Group : ";


gets(d[i].Bloodgroup);
i++;
}while(i<n);

cout<<"\n\nDonors having O Negative Blood";


cout<<"\n******************************"<<endl;
for(j=0;j<n;j++){
if(strcmpi(d[j].Bloodgroup,"O Negative")==0){
flag = 1;
cout<<"\nDonor Number:";
cout<<d[j].DonorNo;
cout<<endl;
cout<<"Donor Name:";
cout<<d[j].DonorName;
cout<<endl;

}
}
if(flag==0){
cout<<"No Donors Available";
}
getch();

}
PROGRAM:20
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
struct employee {
int empNo;
char name[20];
char add[30];
long int phoneNo;
float salary;
};
struct perks{
float DA;
float HRA;
float NetSalary;
};
employee accept(){
employee e1;
cout<<"\nEnter the employee number: ";
cin>>e1.empNo;
cout<<"Enter the name of the employee: ";
gets(e1.name);
cout<<"Enter the address of the employee: ";
gets(e1.add);
cout<<"Enter the phone number of the employee: ";
cin>>e1.phoneNo;
cout<<"Enter the salary of the employee: ";
cin>>e1.salary;
return e1;
}
perks calc(float salary){
perks p1;
p1.DA = 20*salary / 100;
p1.HRA = 25 * salary /100;
p1.NetSalary = salary + p1.DA+ p1.HRA;
return p1;
}
void Display(employee e1){
cout<<"\nEmployee Number: "<<e1.empNo;
cout<<"\nEmployee Name: "<<e1.name;
cout<<"\nEmployee Address: "<<e1.add;
cout<<"\nEmployee Phone Number: "<<e1.phoneNo;
cout<<"\nEmployee Salary: "<<e1.salary;}
void PerkDisp(perks p1){
cout<<setprecision(5)<<"\nDaily Allowance:"<<p1.DA;
cout<<"\nHouse Rent Allowance:"<<p1.HRA;
cout<<"\nNet Salary:"<<p1.NetSalary;
}
void main(){
clrscr();
int n,i;
employee Emp[10];
perks Perk[10];
cout<<"\nEMPLOYEE DATABASE USING STRUCTURE";
cout<<"\nEnter the total number of Employees:";
cin>>n;
for(i=0;i<n;i++){
cout<<"\n";
Emp[i]=accept();
Perk[i]=calc(Emp[i].salary);
}
for(i=0;i<n;i++){
cout<<"\n\n*****************************";
Display(Emp[i]);
PerkDisp(Perk[i]);
cout<<"\n*****************************";
}}

You might also like