Q1 You are required to develop a program that prompts the user to enter an integ
ID: 3628080 • Letter: Q
Question
Q1You are required to develop a program that prompts the user to enter an integer
value (int). The programme should then display the number of bytes used to store
this type of variable.
For the value entered your programme should then display the values of the
individual bytes used to store the value entered.
Q2
Write a program that counts both the total number and number of vowel keys (a,e,i,o,u) pressed until the user hits the ‘!’ key. When the ‘!’ key is pressed the program should display the total key-press count on the screen together with the percentage of vowel keys pressed.
Explanation / Answer
please rate - thanks
CRAMSTER rule- 1 question per post, I was in a good mood
#include <stdio.h>
#include <conio.h>
int main()
{
int i,j;
unsigned int mask=0xf;
size_t size;
printf("enter an integer: ");
scanf("%d",&i);
size=sizeof(i);
printf("%d bytes are used to store the integer %d ",size,i);
for(j=size-1;j>=0;j--)
{printf("byte %d contains hex %x ",j,i&mask);
i/=16;
}
getch();
return 0;
}
---------------------------------------------
since it's early in the semester, I used no functions
#include
#include
int main()
{char c;
int vowel=0, all=0;
printf("enter a vowel ! to exit: ");
c=getchar();
while(c!='!')
{getchar(); //ignore enter key
all++;
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||
c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
vowel++;
printf("enter a vowel ! to exit: ");
c=getchar();
}
printf("total keys pressed: %d ",all);
printf("percentage of vowels: %.2f ",vowel/(double)all*100);
getch();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.