Showing posts with label Functions. Show all posts
Showing posts with label Functions. Show all posts

Friday, March 17, 2023

C Programming. Program to find area and circumference using function.

 Program to find area and circumference using function.

// Program to find area and circumference using function
#include <stdio.h>

float Area(int);
float Circ(int);

int main()
{
    int r;
    float area, circ;
    printf("Enter the radius of a circle : ");
    scanf("%d", &r);
    area = Area(r);
    circ = Circ(r);
    printf("The area of the circle is : %.2f", area);
    printf("\nThe circumference of the circle is : %.2f", circ);
    return 0;
}

float Area(int r)
{
    float area = 3.141 * r * r;
    return area;
}
float Circ(int r)
{
    float circ = 2 * 3.141 * r;
    return circ;
}

Output :

Enter the radius of a circle : 5 The area of the circle is : 78.53 The circumference of the circle is : 31.41

Sunday, January 8, 2023

C Programming. Palindrome function.

Palindrome Function.

Function to check if a string is Palindrome or not.


#include<stdio.h>

void isPalindrome(char str[]);
   

int main(){
    char str[100];
    printf("Enter a string : ");
    gets(str);
    isPalindrome(str);
    return 0;
}

void isPalindrome(char str[]){
    char rev[100];
   
    int c=0,i,id=0;
    for (i=0; str[i]!='\0'; i++){
        c++;
    }
    for (i=c-1; i>=0; i--){
        rev[id]=str[i];
        id++;
    }
    c=0;
    for (i=0; str[i]!='\0'; i++){
        if (rev[i]==str[i]){
            c++;
        }
    }
    if (c==i){
        printf("Palindrom");
    }
    else{
        printf("Not Palindrom");
    }

}

Selection Sort Using C programming.

Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the un...