Advertisement
splash365

practice hsc 2

May 11th, 2024
747
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.43 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int isVowel(char ch)
  4. {
  5.     char vowels[10] = "aeiouAEIOU";
  6.    
  7.     for(int i = 0; i<10; i++)
  8.     {
  9.         if(ch == vowels[i]) return 1;
  10.     }
  11.    
  12.     return 0;
  13. }
  14.  
  15. int main()
  16. {
  17.     char ch;
  18.     scanf("%c", &ch);
  19.    
  20.     if(isVowel(ch)) {
  21.         printf("%c is vowel\n", ch);
  22.     }
  23.     else {
  24.         printf("%c is consonant\n", ch);
  25.     }
  26.    
  27.     return 0;
  28. }
  29.  
  30.  
  31. /*
  32.  
  33. vowels
  34.  
  35. a e i o u A E I O U
  36. 0 1 2 3 ....      9
  37.  
  38. vowels[0]-> 'a'
  39. vowels[1]-> 'e'
  40. ..
  41. vowels[9]-> 'U'
  42.  
  43.  
  44. */
  45.  
  46.  
  47.  
  48.  
  49.  
  50. #include <stdio.h>
  51.  
  52.  
  53. int main()
  54. {
  55.     int n = 4;
  56.    
  57.     for(int i = 1; i<=n; i++)
  58.     {
  59.         int sp = n - i;
  60.         int st = 2 * i - 1;
  61.        
  62.         for(int j = 1; j <= sp; j++) printf(" ");
  63.         for(int j = 1; j <= st; j++) printf("*");
  64.         printf("\n");
  65.     }
  66.    
  67.     for(int i = 1; i<n; i++)
  68.     {
  69.         int sp = i;
  70.         int k = n - i;
  71.         int st = 2 * k - 1;
  72.         for(int j = 1; j <= sp; j++) printf(" ");
  73.         for(int j = 1; j <= st; j++) printf("*");
  74.         printf("\n");
  75.     }
  76.    
  77.     return 0;
  78. }
  79.  
  80.  
  81. /*
  82.  
  83. 1
  84. 22
  85. 333
  86. 4444
  87. 55555
  88.  
  89. 2 * i - 1
  90.  
  91. N = 4
  92.  
  93.    *       [sp = 3, st = 1]
  94.   ***      [sp = 2, st = 3]
  95.  *****     [sp = 1, st = 5]
  96. *******    [sp = 0, st = 7]
  97.  *****     [sp = 1, st = 5] i = 1
  98.   ***      [sp = 2, st = 3]
  99.    *       [sp = 3, st = 1]
  100.    
  101.    
  102.    n = 4
  103.    5 i = 3
  104.    3 i = 2
  105.    1 i = 1
  106.    
  107.    
  108.    
  109. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement