C Language

#include<stdio.h> /* Program to print Hello World */ int main() { printf(“Hello World”); return 0; } A C program basically consist of following parts:: Pre-processor Commands Comment Functions variables Statements and expressions Pre-processor Commands : First line of the program #include is a pre-processor commands.  Preprocessor directives are lines included in the code of programs preceded…

Pyramid and Pattern in C Language

Pyramid and Pattern 1) * ** *** **** ***** #include<stdio.h> int main(){ int i, j,rows; printf(“Enter number of rows: “); scanf(“%d”,&rows); for(i=1;i<=4;i++) { for(j=1;j<=i;j++) { printf(“*”); } printf(“\n”); } return 0; } 2) 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 #include<stdio.h> int main(){ int i, j,rows; printf(“Enter…

Library Functions isalnum Check if character is alphanumeric isalpha Check for Alphabetic iscntrl Test for Control Character isdigit Test for Digit isgraph Test for Graphical Character (does not include a space) islower Test for Lowercase Letter isprint Test for Printing Character (does include a space) ispunct Test for Punctuation Character isspace Test for White-Space Character…

1. C++ Program to calculate sum and average of two numbers

#include<iostream> using namespace std; int main() { int a, b, sum; float avg; cout<<“Enter Two Numbers”; cin>>a>>b; sum = a + b; avg = sum / 2; cout<<“Sum of two numbers :: ” <<sum<<endl; cout<<“Avg of two numbers :: “<<avg; return 0; }

Check whether a number is even or odd

#include<stdio.h&t; int main() { int num; printf(“Enter any number :: “); scanf(“%d”,&num); if(num%2 == 0) printf(“%d is Even Number”,num); else printf(“%d is odd Number”,num); return 0; } Output:: Enter any number :: 11 11 is odd Number or Enter any number :: 10 10 is Even Number

Swap two numbers – XOR Operator

#include<stdio.h> /* Swap two numbers @kodingkeys@keycomputer */ int main() { int num1, num2, temp; printf(“Enter two numbers to swap ::”) ; scanf(“%d%d”,&num1, &num2); temp = num1; num1 = num2; num2 = temp; printf(“Swapped numbers %d – %d”,num1, num2) ; return 0; } Output:: Enter two numbers to swap :: 11 12 Swapped numbers 12 – […]

Swap two numbers – without using third Variable

#include<stdio.h> /* Swap two numbers @kodingkeys@keycomputer */ int main() { int num1, num2, temp; printf(“Enter two numbers to swap ::”) ; scanf(“%d%d”,&num1, &num2); temp = num1; num1 = num2; num2 = temp; printf(“Swapped numbers %d – %d”,num1, num2) ; return 0; } Output:: Enter two numbers to swap :: 11 12 Swapped numbers 12 – […]

Swap two numbers – using third Variable

#include<stdio.h> /* Swap two numbers @kodingkeys@keycomputer */ int main() { int num1, num2, temp; printf(“Enter two numbers to swap ::”) ; scanf(“%d%d”,&num1, &num2); temp = num1; num1 = num2; num2 = temp; printf(“Swapped numbers %d – %d”,num1, num2) ; return 0; } Output:: Enter two numbers to swap :: 11 12 Swapped numbers 12 –…

Sizeof Function

#include<stdio.h> /* Sizeof function @kodingkeys@keycomputer */ int main() { int i; float f; double d; char c; // Sizeof operator is used to evaluate the size of a variable printf(“Size of int: %ld bytes\n”,sizeof(i)); printf(“Size of float: %ld bytes\n”,sizeof(f)); printf(“Size of double: %ld bytes\n”,sizeof(d)); printf(“Size of char: %ld byte\n”,sizeof(c)); return 0; } Output: Size of…

Computer Quotient and Remainder

#include <stdio.h> /* Compute Quotient and Remainder @kodingkeys@keycomputer */ int main() { int num1, num2, q, r; printf(“Enter Divident and Divisor :: “); scanf(“%d%d”,&num1,&num2); // Compute quotient q = num1/ num2; // Compute remainder r = num1 % num2; printf(“Quotient = %d\n”, q); printf(“Remainder = %d”, r); return 0; }  

ASCII Value of a Character

#include<stdio.h> /* ASCII Value of a Character @kodingkeys@keycomputer */ int main() { char c; printf(“Enter a character: “); scanf(“%c”,&c); printf(“ASCII value of %c = %d”, c, c); return 0; }

Multiply two Floating Point Numbers

#include <stdio.h> /* Multiplying two floating point numbers @kodingkeys@keycomputer */ int main() { double num1, num2, result; printf(“Enter two numbers: “); scanf(“%lf %lf”, &num1, &num2; result = num1 * num2; printf(“Product = %.2lf”, result); return 0; }