1) Write a function that reverses the given string. 2) Write a function that rea
ID: 3690936 • Letter: 1
Question
1) Write a function that reverses the given string. 2) Write a function that reads a sentence and prints all the words in the sentence. 3) Write a function that returns the grade of the student. Input to the function is number and grading distribution is – >90 A , >80B, >70C and soon . 4) Write a function that returns the number of vowels in a string. 5) Write a function that takes a square matrix and returns the determinant of a the matrix. 6) Write a program to find the Highest Common Factor using recursion.Explanation / Answer
1) Function that reverses the given string
# include <stdio.h>
# include <conio.h>
int main() {
char arr[100];
printf("Enter a string to reverse ");
gets(arr);
strrev(arr);
printf("Reverse of entered string is %s ", arr);
}
return 0;
}
2)function that reads a sentence and prints all words in sentence
# include <stdio.h>
int main(void) {
char s[256];
int i=0;
printf("Enter a string :");
gets(s);
while( s[i] ) {
if( s[i]==' ')
printf(" ");
else
printf("%c", s[i]);
i++;
3)function that returns grades of a student
# include <stdio.h>
int main(void) {
int num;
printf("Enter your mark");
scanf("%d",num);
printf("You entered %d,num);
if(num>=90) {
printf("You got A grade");
}
else if(num >=80 && num<90) {
printf("You got B grade");
}
else if(num>=70 && num<80) {
printf("You got C grade");
}
else if(num>=60 && num<70) {
printf("You got D grade");
}
else if(num>=50 && num<60) {
printf("You got E grade");
}
else if(num>=40 && num<50) {
printf("You got F grade");
}
else if(num<40) {
printf("You failed in the exam");
}
return 0;
}
4) function that return the number of vowels
# include <stdio.h>
# include <conio.h>
void main() {
char ch [10];
int i,count=0;
clrscr();
printf("Enter the string ");
gets(ch);
for(i=0;ch[i] !='';i++)
{
if(ch[i] =='a' // ch[i]=='e' // ch[i]=='i' // ch[i]=='o' // ch[i]=='u' // ch[i] =='A' // ch[i]=='E' // ch[i]=='I' // ch[i]=='O' // ch[i]=='U')
{
count++;
}
}
printf("Vowels =%d", count);
getch();
}
5)function that takes a square matrix and returns deteminant matrix
# include <stdio.h>
void main() {
int a[] [],i,j;
long determinant;
prontf("Enter the four elements of matrix :");
for(i=0;i<2;i++)
for(j=0;j<2;j++)
scanf("%d",&a[i][j]);
printf(" The matrix is ");
for(i=0;i<2;i++) {
printf(" ");
for(j=0;j<2;j++)
printf("%d ", a[i][j]);
}
determinant=a[0][0]*a[1][1]-a[1][0]*a[0][1];
printf("Determinant of matrix : %ld", determinant);
return 0;
}
6) program to find HCF using recurssion
# include <stdio.h>
int hcf(int,int);
int main() {
int a,b, result;
printf("Enter two numbers to find their HCF :");
scanf("%d%d", &a.&b);
result=hcf(a,b);
printf(The hcf of %d and %d is %d. ",a,b,result);
}
int hcf(int a,int b) {
while(a!=b)
{
if(a>b)
{
return hcf(a-b,b);
}
else
{
return hcf(a,b-a);
}
}
return a;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.