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 find the length of a String without using function strlen()

#include <stdio.h> int main() { char str[100],i; printf(“Enter a string: \n”); scanf(“%s”,str); for(i=0; str[i]!=’\0′; ++i); printf(“\nLength of input string: %d”,i); return 0; }  

C Program to find the Sum of First n Natural numbers

#include <stdio.h> int main() { int n, count, sum = 0; printf(“Enter the value of n(positive integer): “); scanf(“%d”,&n); for(count=1; count <= n; count++) { sum = sum + count; } printf(“Sum of first %d natural numbers is: %d”,n, sum); return 0; }  

C program to print map of India [ C Tutorials ]

The string is a run-length encoding of the map of India. Alternating characters in the string stores how many times to draw a space, and how many times to draw an exclamation mark consecutively.

// C program to print map of India
#include <stdio.h>

int main()
{
int a = 10, b = 0, c = 10;

// The encoded string after removing first 31 characters
// Its individual characters determine how many spaces
// or exclamation marks to draw consecutively.
char* str = “TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq ”
“TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL”
“OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm ”
“SOn TNn ULo0ULo#ULo-WHq!WFs XDt!”;

while (a != 0)
{
// read each character of encoded string
a = str[b++];
while (a– > 64)
{
if (++c == 90) // ‘Z’ is 90 in ascii
{
// reset c to 10 when the end of line is reached
c = 10;     // ‘\n’ is 10 in ascii

// print newline
putchar(‘\n’); // or putchar(c);
}
else
{
// draw the appropriate character
// depending on whether b is even or odd
if (b % 2 == 0)
putchar(‘!’);
else
putchar(‘ ‘);
}
}
}

return 0;
}

Write a C program to calculate the distance between two cities

C Programming Tutorial

Problem Statement: The distance between two cities (in km.) is input through the keyboard. Write a C program to convert and print this distance in meters, feet, inches and centimeters. Answer: /* Conversion of distance */ #include <stdio.h> #include <conio.h> main() { float km, m, cm, ft, inch; clrscr(); /* To clear the screen */ … Read more