Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

NAME-RASHMI KISKU ROLL NO-2004030

ECE1A CSL3501

PROGRAM 1:

Write a C program which implement the following functions,

 take a  user entered name and print it in reverse order.


 Print the number of consonants in the given name. 
 Arrange the letters in the given name in reverse alphabatical order. 

SOLUTION:

INPUT-

 #include <stdio.h>
 #include <string.h>
  
 void printReverse(char str[])
 {
      int i ;
        int len = strlen(str);
     printf("The reverse string is: ");
     for(i = len - 1; i >= 0; i--) 
     {
          printf("%c", str[i]);
     }
     printf("\n");
 }
  
  
  void count_consonant(char* str)
 { 
     int vowels = 0, consonants = 0;
     int i;
     char ch;
    
     for (i = 0; str[i] != '\0'; i++) {
        ch = str[i];
   
         if (ch == 'a' || ch == 'A'
             || ch == 'e' || ch == 'E'
             || ch == 'i' || ch == 'I'
             || ch == 'o' || ch == 'O'
             || ch == 'u' || ch == 'U')
             vowels++;
         else if (ch == ' ')
             continue;
         else
           consonants++;
     }
     printf("Consonants: %d", consonants);
 }

  void reverse_alpha(char string[])
 { 
 char temp;
     int i, j;
     int n = strlen(string);
      int len = strlen(string);
     for (i = 0; i < n-1; i++) {
         for (j = i+1; j < n; j++) {
             if (string[i] > string[j]) {
                     temp = string[i];
                     string[i] = string[j];
                     string[j] = temp;
             }
         }
     }
  for(i = len - 1; i >= 0; i--) 
     {
          printf("%c", string[i]);
     }
 }
 int main()
 {
     char str[100];
       scanf("%[^\n]s",str); 
   printReverse(str);
    count_consonant(str);
 printf("\nThe string in reverse alphabatical : ");
     reverse_alpha(str);
     return 0;
 }
OUTPUT-
PROGRAM 2:

Write a C program to take a number from user and print inverted triangle of stars where the number
of stars in the first line must be equal to the number given by user.

SOLUTION:

INPUT-

#include<stdio.h>
int main()
{
  int n, i, j, k;

  printf("Enter the number:");
  scanf("%d",&n);
  for(i=n;i>=1;i--)
  {
    for(j=1;j<=n-i;j++) printf(" ");
    for(k=1;k<=i;k++) printf("* ");

    printf("\n");
  }

  return 0;
}

OUTPUT-

You might also like