Four Programs Related To C++

Pythonpedia
Four Programs Related To C++
1.Program to find the number entered is Armstrong or not?

Program:-

Pythonpedia
Pythonpedia
Code:-

#include<iostream.h>
#include<conio.h>
int main ()
{
clrscr();
int arm=0,a,b,c,d,num;
cout<<”/nEnter the number : “;
cin>>num;
d=num;
while (num>0)
{
a=num%10;
num=num/10;
arm=arm+a*a*a;
}
if (arm==d)
{
cout<<”/nThe number “<<d<<” is Armstrong “;
}
else
{
cout<<”/nThe number “<<d<<” is not Armstrong “;
}
getch();
return 0;
}

Output:-
Pythonpedia
Enter the number : 255
The number 225 is not Armstrong

2.Program to find factorial of a number entered?

Program:-

Pythonpedia
Code:-
#include<iostream.h>
#include<conio.h>
int main ()
{
clrscr();
int num,I,fact=1;
cout<<”/nEnter the number : “;
cin>>num;
for(i=num;i>0;i--)
{
fact=fact*I;
}
cout<<”/nFactorial of number “<<num<<” is “<<fact;
getch();
return 0;
}

Output:-

Pythonpedia
Enter the number : 5
Factorial of 5 is 120

3.Program to find Fibonacci series up to terms entered?


Program:-

Pythonpedia
Code:-

#include<iostream.h>
#include<conio.h>int main ()
{
clrscr();
int terms,t1=0,t2=1,t3;
cout<<”/nEnter the terms : “;
cin>>terms;
cout<<t1<<”/t”<<t2<<”/t”;
for (int i=2;i<terms;i++)
{
t3=t1+t2;
cout<<t3<<”/t”;
t1=t2;
t2=t3;
}
getch();
return 0;
}
Output:-

Pythonpedia
Enter the terms : 6
0       1       1       2       3       5


4.Program to find or calculate the grade of student?
Program:-

Pythonpedia
Code:-
#include<iostream.h>
#include<conio.h>
struct student
{
int rollno;
char name[30];
int marks[3];
char grade;
};
int main()
{
clrscr();
student st[2];
void getstudent(student st1[],int size);
void calcgrade(student st1[],int size);
void print(student st1[],int size);
getstudent(st,2);
calcgrade(st,2);
prints(st,2);
getch();
return o;
}
void getstudent(student st1[],int size)
{
for(int i=0;i<size;i++)
{
cout<<”/nEnter rollno of student “;
cin>>st1[i].rollno;
cout<<”/nEnter the name of student “;
cin>>st1[i].name;
for(int j=0;j<3;j++)
{
cout<<”/nEnter the marks “;
cin>>st1[i].marks[j];
}
}
}
void calcgrade(student st1[],int size)
{
int sum[2],avg[2];
for(int i=0;i<size;i++){
for(int j=0;j<3;j++)
{
sum[i]=sum[i]+st1[i].marks[j];
avg[i]=sum[i]/3;
}
if(avg[i]>80)
{
st1[i].grade=’A’;
}
else if(avg[i]>70)
{
st1[i].grade=’B’;
}
else
{
st1[i].grade=’C’;
}
}
}
void prints(student st1[]’int size)
{
cout<<”/nThe rollno of student is “<<st1[i].rollno;
cout<<”/nThe name of student is “<<st1[i].name;
cout<<”/nThe grade of student is “<<st1[i].grade;
}
}
Output:-

Pythonpedia
Enter rollno of student 1
Enter the name of student Surajit
Enter the marks 89
Enter the marks 98
Enter the marks 97
Enter rollno of student 2
Enter the name of student akriti
Enter the marks 99
Enter the marks 96
Enter the marks 99
The rollno of student is 1
The name of student is Surajit
The grade of student is A
The rollno of student is 2
The name of student is akriti
The grade of student is A
-Thank you

Comments

Popular posts from this blog