Author: learnconline

Program to Demonstrate Typecasting in C 4

Program to Demonstrate Typecasting in C

Here is a program to demonstrate typecasting in C programming language. #include #include void main(){ float result; int num1, num2; clrscr(); num1 = 10; num2 = 3; result = num1/num2; printf(“\nBefore Typecasting: %f”,result); /* As num1 and num2 are declared as int, it will return int value and it will get stored in the variable “result” as float i.e. 3.000000 To solve this problem we can use typecasting. */ result = (float)num1/num2; printf(“\nAfter Typecasting: %f”,result); getch(); } Output: Before Typecasting: 3.000000 After Typecasting: 3.333333

Program to check if a number is Armstrong or not 4

Program to check if a number is Armstrong or not

Definition (Armstrong Number): An n-digit number equal to the sum of the nth powers of its digits. Example: 153 = 13 + 53 + 33 1634 = 14 + 64 + 34 + 44 #include<stdio.h> #include<math.h> int main(){ long int num =153, count = 0, i, temp1, temp2, temp3 = 0; clrscr(); printf(“Enter the number: “); scanf(“%ld”,&num); if(num <= 0){ printf(“\nEnter the number greater than 0”); return 0; } temp1 = temp2 = num; while(temp1!=0){ temp1=temp1/10; count++; } for(i=0;i < count; i++) { temp3 = temp3 + pow((temp2%10),count); temp2 = temp2/10; } if(num == temp3) { printf(“\n %d is an...

String handling functions in C 22

String handling functions in C

In this article, you will understand different string handling functions in C. By the end of this article, you will learn how to write C programs to perform the following string operations –  find the length of a string, compare 2 strings, copy one string to another, concatenate 2 strings, etc. Following are some of the useful string handling functions in C. strlen() strcpy() strncpy() strcat() strncat() strcmp() strncmp() strcmpi() strncmpi() These string handling functions are defined in string.h header file. Hence you need to include this header file whenever you use these string handling functions in your C program....

Program to Calculate Length of a String (Using strlen in-built function) 5

Program to Calculate Length of a String (Using strlen in-built function)

#include #include #include void main(){ int strlength; char *str; clrscr(); printf(“\nEnter the string: “); gets(str); strlength=strlen(str); printf(“\nThe length of the string is %d.”,strlength); getch(); } Output: Enter the string: Learn C Online The length of the string is 14.

Program to Calculate Length of a String (without using strlen in-built function). 30

Program to Calculate Length of a String (without using strlen in-built function).

#include #include void main(){ char *str; int count = 0,i; clrscr(); printf(“\nEnter the String: “); gets(str); for(i=0;str[i]!=’\0′;i++){ count++; } printf(“\nThe length of the string is %d.”,count); getch(); } Output: Enter the String: Learn C Online The length of the string is 14.

Strings in C Programming Language 19

Strings in C Programming Language

A string in C is a series of characters in a group that occupy contiguous memory. A group of characters (Alphabets, digits and special characters) is called as a string. Example 1: “Thank you for visiting www.learnconline.com” “www.learnconline.com is excellent site for beginners. This is example of strings in C.” A string in C should always be enclosed with in double quotes (“). If single quote is used then it is treated as character. Hence ‘A’ is different from “A”. Every string ends with a null character (‘\0’). Note that \0 is a single character. So when it has to...

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet