C Program to find largest element of an Array

#include <stdio.h> largest_element(int arr[], int num) { int i, max_element; max_element = arr[0]; for (i = 1; i < num; i++) if (arr[i] > max_element) max_element = arr[i]; return max_element; } int main() { int arr[] = {1, 24, 145, 20, 8, -101, 300}; int n = sizeof(arr)/sizeof(arr[0]); printf(“Largest element of array is %d”, largest_element(arr, … Read more

C Program to arrange numbers in ascending order

  #include <stdio.h> void sort_numbers_ascending(int number[], int count) { int temp, i, j, k; for (j = 0; j < count; ++j) { for (k = j + 1; k < count; ++k) { if (number[j] > number[k]) { temp = number[j]; number[j] = number[k]; number[k] = temp; } } } printf(“Numbers in ascending order:\n”); … Read more

C Program to calculate Area and Circumference of Circle

#include <stdio.h> int main() { int circle_radius; float PI_VALUE=3.14, circle_area, circle_circumf; printf(“\nEnter radius of circle: “); scanf(“%d”,&circle_radius); circle_area = PI_VALUE * circle_radius * circle_radius; printf(“\nArea of circle is: %f”,circle_area); circle_circumf = 2 * PI_VALUE * circle_radius; printf(“\nCircumference of circle is: %f”,circle_circumf); return(0); }  

C Program for bubble sorting

#include<stdio.h> int main(){ int count, temp, i, j, number[30]; printf(“How many numbers are u going to enter?: “); scanf(“%d”,&count); printf(“Enter %d numbers: “,count); for(i=0;i<count;i++) scanf(“%d”,&number[i]); for(i=count-2;i>=0;i–){ for(j=0;j<=i;j++){ if(number[j]>number[j+1]){ temp=number[j]; number[j]=number[j+1]; number[j+1]=temp; } } } printf(“Sorted elements: “); for(i=0;i<count;i++) printf(” %d”,number[i]); return 0; }  

Selection Sort Program in C

#include<stdio.h> int main(){ int i, j, count, temp, number[25]; printf(“How many numbers u are going to enter?: “); scanf(“%d”,&count); printf(“Enter %d elements: “, count); for(i=0;i<count;i++) scanf(“%d”,&number[i]); // Logic of selection sort algorithm for(i=0;i<count;i++){ for(j=i+1;j<count;j++){ if(number[i]>number[j]){ temp=number[i]; number[i]=number[j]; number[j]=temp; } } } printf(“Sorted elements: “); for(i=0;i<count;i++) printf(” %d”,number[i]); return 0; }

C Program to check whether the given integer is positive or negative

#include <stdio.h> void main() { int num; printf(“Enter a number: \n”); scanf(“%d”, &num); if (num > 0) printf(“%d is a positive number \n”, num); else if (num < 0) printf(“%d is a negative number \n”, num); else printf(“0 is neither positive nor negative”); }

C Program to check if a number is palindrome or not

  #include <stdio.h> int main() { int num, reverse_num=0, remainder,temp; printf(“Enter an integer: “); scanf(“%d”, &num); temp=num; while(temp!=0) { remainder=temp%10; reverse_num=reverse_num*10+remainder; temp/=10; } if(reverse_num==num) printf(“%d is a palindrome number”,num); else printf(“%d is not a palindrome number”,num); return 0; }

pointer example program in C

pointer c program example

pointer example program in C What would be the output of following pointer program written in c   main( ) { int a = 10, b = 20 ; swapr ( &a, &b ) ; printf ( “\na = %d b = %d”, a, b ) ; } swapr( int *x, int *y ) { … Read more

c program example Passing values between functions

c program example function and value pass to function 1

c program example Passing values between functions c program example function and value pass to function 1   main( ) { int i = 45, c ; c = check ( i ) ; printf ( “\n%d”, c ) ; } check ( int ch ) { if ( ch >= 45 ) return ( … Read more

write a C program to calculate the sum of its digits

C Programming Tutorial

Problem Statement: If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. Answer: /* Sum of digits of a 5 digit number*/ #include<stdio.h> #include<conio.h> main() { int num,a,n; int sum=0; /* this has been initialised to zero otherwise it will contain a garbage value */ clrscr(); … Read more