C++ Programming Problems
C++ Programming Problems
Group Assignment
S/no Full Name ID Number
1 Duol Koang 1201489
2 Bol Michael 1205702
3 Degaga Girma 1201302
4 Meti Girma 1203956
5 Solomon Aga 1204993
6 Adisu Terfu 1208761
#include<iostream.h>
void main()
{
for(int i=10;i<=49;i++)
{
cout<<i<<" ";
if(i%10==9)
{
cout<<endl;
}
}
}
4. Write a C++ program that counts the number of digits in an integer number.
For example; 23,498 has five digits.
#include<iostream.h>
void main()
{
int num,x;
int count=0;
cout<<"Enter any number:";
cin>>num;
x=num;
while(x!=0)
{
count++;
x/=10;
}
cout<<num<<" has "<<count<<" digits.";
}
2|B y D uol K. Tho ng
5. Write a C++ application that can compute the letter grade of a student after
accepting the student’s mid and final mark. The program should only accept
mid result [0-40] and final [0- 60]. If the data entered violates this rule, the
program should display that the user should enter the mark in the specified
range. The program is also expected to run until the user refuses to continue.
#include<iostream,h>
void main()
{
int mid, final;
cout<<"Enter your mark from mid:";
cin>>mid;
while(mid>40 || mid<0)
{
cout<<"Enter the mark in specific range!\n";
return(0);
}
cout<<"Enter your mark from final:";
cin>>final;
while(final>60 || final<0)
{
cout<<"Enter the mark in specific range!\n";
return(0);
}
int sum=mid+final;
if(sum>=90 && sum<=100)
{
cout<<"Your grade is: A";
}
else if(sum>=80 && sum<90)
{
cout<<"Your grade is: B";
}
else if(sum>=70 && sum<80)
{
cout<<"Your grade is: C";
}
else if(sum>=60 && sum<70)
{
cout<<"Your grade is: D";
}
3|B y D uol K. Tho ng
else
{
cout<<"Your grade is: F";
}
}
6. Write a C++ program that accepts a positive number from the user and
displays the factorial of that number. Use for loops to find the factorial of the
number.
#include<iostream.h>
void main()
{
int number,fact=1;
7. Write a C++ code that computes the sum of the following series. Sum = 1! +
2! + 3! + 4! + …n!. The program should accept the number from user.
#include<iostream.h>
void main()
{
int n,fact=1,sum=0;
cout<<"Enter any number:";
cin>>n;
for(int i=1;i<=n;i++)
{
fact=fact*i;
sum=sum+fact;
}
cout<<"The sum is:"<<sum;
}
4|B y D uol K. Tho ng
8. Using the ASCII table numbers, write a program to print the following
output, using a nested for loop. (Hint: the outer loop should loop from 1 to 5,
and the inner loop’s start variable should be 65, the value of ASCII “A”).
A
AB
ABC
ABCD
ABCDE
#include<iostream.h>
void main()
{
int i,j;
for(i='A';i<='E';i++)
{
for(j='A';j<=i;j++)
{
cout<<char(j);
}
cout<<endl;
}
}
9. Write a C++ program that displays the following output using their ASCII
values.
a
bc
def
gehi
jklmn
opqrst
#include<iostream.h>
void main()
{
char alphabet='a';
5|B y D uol K. Tho ng
for(int i=1;i<=6;i++)
{
for(int j=1;j<=i;j++)
{
cout<<alphabet++;
}
cout<<endl;
}
}
10. Write a C++ program that will print the following shapes.
A. * B. ***** C. *
** **** ***
*** *** *****
**** ** *******
***** * *********