1. The division of positive integers can be considered as repetitive subtraction
ID: 3778128 • Letter: 1
Question
1. The division of positive integers can be considered as repetitive subtraction of the divisor from the dividend until no more subtractions will result in a positive remainder. For example, the divisor 5 can be subtracted from the dividend 23 exactly 4 times, ending with a remainder of 3. Put this method to use. Write a program that prompts the user to enter a 3-digit integer and a 2-digit integer. Then, use a while loop to determine the result of dividing the 3-digit number by the 2-digit number. Display the quotient and the remainder. NOTE: You must achieve the desired result without using a / operator or a % operator.
SAMPLE OUTPUT
Enter a 3-digit integer 127
Now, enter a 2-digit integer 25
Answer is 5 with remainder 2
3. Write a program that prompts the user to enter his/her full name. Then:
display the name backwards on one line
output the number of vowels in the name (lower case and upper case)
output the number of consonants in the name (lower case and upper case)
SAMPLE OUTPUT
Enter your full name, please James Gosling
g n i l s o G s e m a J
Your name contains 4 vowels and 8 consonants
Explanation / Answer
#include<stdio.h>
void main()
{
int n, d, count=0;
printf("Enter a 3-digit integer ");
scanf("%d",&n);
printf(" Now, enter a 2-digit integer ");
scanf("%d",&d);
while(n>d)
{
n-=d;
count++;
}
printf("Answer is %d with remainder %d", count,n);
}
#include<stdio.h>
#include<math.h>
void main()
{
int i;
printf(" Angle Sine Cosine Tangent ");
printf(" ----- ---- ------ ------- ");
for(i=0;i<=90;i=i+5)
{
printf("%12d",i);
printf("%12f",sin(i));
printf("%12f",cos(i));
printf("%12f ",tan(i));
}
}
#include<stdio.h>
#include<string.h>
void main()
{
char name[]="";
int i,v=0,c=0,len=0;
printf("Enter your full name, please ");
fgets(name,100,stdin);
len=strlen(name);
for(i=len-1;i>=0;i--)
{
printf("%c ",name[i]);
}
for(i=0;i<len;i++)
{
if(name[i]=='A' || name[i]=='a' || name[i]=='E' || name[i]=='e' || name[i]=='I' || name[i]=='i' || name[i]=='O' || name[i]=='o' || name[i]=='U' || name[i]=='u')
v++;
else if(name[i]!=' ')
c++;
}
printf(" Your name contains %d vowels and %d consonants",v,c);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.