Below is my lecturer give me the question, i just can handle the first questio, but i think my logic thinking is not so good! , so hope some one can help me to solve, thanks!
1.)write a recursive function that takes a parameter a non negative integer and generatesthe following pattern of stars. If the non-negative integer is 4, then the pattern generated is:
****
***
**
*
*
**
***
****
Also write a program that prompts the user ti enter the number of lines in the pattern and uses the recursive function to generate the pattern. For example, specifying 4 as number of lines generates the above pattern.
*Question1, i solved already, but i think the logic is not so good, so post at here to discuss.
(Answer Question 1)
Code:#include <stdio.h> void asterisks1(int x) { int i; if (x ==0 ) return; for (i=0;i<x;i++) printf ("*"); printf("\n"); asterisks1(x-1); } void asterisks2(int a,int b) { int i; if (a ==b+1 ) return; else for (i=0;i<a;i++) printf ("*"); printf("\n"); asterisks2(a+1,b); } int main() { int value; scanf("%d",&value); asterisks1(value); asterisks2(1,value); }
2.) Write a program that uses a stack to print the prime factors of a positive integer in descending order using the stack.
3.) Write a programing that reads a line of text, changes each uppercase letter to lowercase and places each letter both in a Queue and onto a stack. The program should then verify whether the line of text is a palindrome.
4.)write a program to test:
a.) The selection sort algorithm.
b.) The insertion sort algorithm.
for linked lists.