• Complain

Gupta - 100+ Most Important C Programs with Output: for Students & Teachers

Here you can read online Gupta - 100+ Most Important C Programs with Output: for Students & Teachers full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2016, publisher: R.K.G, genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

No cover
  • Book:
    100+ Most Important C Programs with Output: for Students & Teachers
  • Author:
  • Publisher:
    R.K.G
  • Genre:
  • Year:
    2016
  • Rating:
    3 / 5
  • Favourites:
    Add to favourites
  • Your mark:
    • 60
    • 1
    • 2
    • 3
    • 4
    • 5

100+ Most Important C Programs with Output: for Students & Teachers: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "100+ Most Important C Programs with Output: for Students & Teachers" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Gupta: author's other books


Who wrote 100+ Most Important C Programs with Output: for Students & Teachers? Find out the surname, the name of the author of the book and a list of all author's works by series.

100+ Most Important C Programs with Output: for Students & Teachers — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "100+ Most Important C Programs with Output: for Students & Teachers" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make

Copyright 2016 by Rohit Gupta- All rights reserved. This book is copyright protected. This is only for personal use. You cannot amend, distribute, sell, use, quote or paraphrase any part or the content within this book without the consent of the author or copyright owner. Except as permitted under India Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopying, microfilming, and recording, or in any information storage or retrieval system, without written permission from the publishers. This book is a work of pure practical knowledge.

Any resemblance to other book is entirely coincidental.
Table of Contents


1. Write a program to perform addition, subtraction, multiplication and division.
#include #include int main() { int first, second, add, subtract, multiply; float divide; printf("Enter two integers:\n"); scanf("%d%d", &first, &second); add = first + second; subtract = first - second; multiply = first * second; divide = first / (float)second; printf("Sum = %d\n",add); printf("Difference = %d\n",subtract); printf("Multiplication = %d\n",multiply); printf("Division = %.2f\n",divide); return 0; getch(); } Sample Output: Enter two integers: Sum = 8 Difference = -2 Multiplication = 15 Division = 0.60

2. How to add two numbers without using the plus operator?
#include #include int main() { int a,b; int sum; printf("Enter any two integers: "); scanf("%d%d",&a,&b); sum = a - ~b -1; printf("Sum of two integers: %d",sum); return 0; getch(); } Sample output: Enter any two integers: 5, 10 Sum of two integers: 15 Formula:
In C ~ is 1's complement operator. This is equivalent to: ~b = -(b + 1) So, a - ~b -1 = a-[-(b + 1)] -1 = a + b + 1 - 1 = a + b

How to subtract two numbers without using the subtraction operator ?
#include #include int main() { int a,b; int subtract; printf("Enter any two integers: "); scanf("%d%d",&a,&b); subtract = a + ~b + 1; printf("Difference of two integers: %d",subtract); return 0; getch(); } Sample Output: Enter any two integers: 5, 4 Difference of two integers: 1 Formula:
In C ~ is 1's complement operator. This is equivalent to: ~b = -(b + 1) So, a + ~b +1 = a+[-(b + 1)] +1 = a - b - 1 + 1 = a - b

4.

Write a program for swapping of two numbers.

#include #include int main() { int a,b,temp; printf("Enter any two integers: "); scanf("%d%d",&a,&b); printf("Before swapping: a = %d, b=%d",a,b); temp = a; a = b; b = temp; printf("\nAfter swapping: a = %d, b=%d",a,b); return 0; getch(); } Sample output: Enter any two integers: 3, 6 Before swapping: a = 3, b=6 After swapping: a = 6, b=6

5. Write a program to add digits of a number or calculate sum of digits.
#include #include int main() { int num,sum=0,r; printf("Enter a number: "); scanf("%d",&num); while(num) { r=num%10; num=num/10; sum=sum+r; } printf("Sum of digits of number: %d",sum); return 0; getch(); } Sample output: Enter a number: 123 Sum of digits of number: 6

6. Write a program to print complex number.
#include #include int main() { int a,b; printf("Enter the real part of complex number: "); scanf("%d",&a); printf("Enter the imaginary part of complex number: "); scanf("%d",&b); printf("\nComplex number is: %d%+di",a,b ); return 0; getch(); } Sample output: Enter the real part of complex number: 4 Enter the imaginary part of complex number: 2 Complex number is: 4+2i Complex numbers definition: Complex numbers are two dimensional numbers i.e. it consists real part and imaginary part. Complex numbers are written as a + ib Where a and b are real numbers and i = -1

7. Write a program to check whether input alphabet is a vowel or not.
#include #include int main() { char ch; printf("Enter a character:\n"); scanf("%c", &ch); if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch =='o' || ch=='O' || ch == 'u' || ch == 'U') printf("%c is a vowel.\n", ch); else printf("%c is not a vowel.\n", ch); return 0; getch(); } Sample Output: Enter a character: i i is a vowel

8.

Write a program to check if given integer is positive or negative.

#include #include int main() { int number; printf("Enter a number: \n"); scanf("%d", &number); if (number >= 0) printf("%d is a positive number \n", number); else printf("%d is a negative number \n", number); getch(); } Sample Output: Enter a number: -4 -4 is negative number

9. Write a program to find the area of a trapezium.
#include #include int main() { float b1,b2,h; float area; printf("Enter the size of two bases and height of the trapezium : "); scanf("%f%f%f",&b1,&b2,&h); area = 0.5 * ( b1 + b2 ) * h ; printf("Area of trapezium is: %.3f",area); return 0; getch(); } Sample output: Enter the size of two bases and height of the trapezium: 5, 8, 3 Area of trapezium is: 19.500 Formula of area of trapezium: Area = (1/2) * (a + b) * h

10. Write a program for swapping of two numbers using function (call by value).
#include #include void swap(int a, int b) { int temp; temp = a; a = b; b = temp; } int main() { int num1 = 10, num2 = 30; printf("Before swapping:\n num1 = %d\n num2 = %d\n", num1, num2); swap(num1, num2); printf("After swapping:\n num1 = %d\n num2 = %d \n", num2, num1); return 0; getch(); }
Sample Output: Before swapping: num1 = 10 num2 = 30 After swapping: num1 =30 num2 = 10

11. Write a program to find greatest number between three numbers.
#include #include int main() { int a,b,c; printf("\nEnter 3 numbers: "); scanf("%d %d %d",&a,&b,&c); if(a-b>0 && a-c>0) printf("\nGreatest is a :%d",a); else if(b-c>0) printf("\nGreatest is b :%d",b); else printf("\nGreatest is c :%d",c); return 0; getch(); } Sample output: Enter 3 numbers: 2, 6, 4 Greatest is b: 6

12. Write a program to find greatest number among four numbers by ternary operator.
# include # include main( ) { int a,b,c,d,big; printf("Enter value a:"); scanf("%d",&a); printf("Enter the value of b:"); scanf("%d",&b); printf("Enter the value of c:"); scanf("%d",&c); printf("Enter the value of d:"); scanf("%d",&d); big=(a>b)?(a>c)?(a>d)?a:d:(c>d)?c:d:(b>c)?(b>d)?b:d:(c>d)?c:d; printf("Biggest of the given 4 numbers is: %d",big); getch(); } Sample output: Enter value a: 8 Enter the value of b: 4 Enter the value of c: 9 Enter the value of d: 6 Biggest of the given 4 numbers is: 9 Ternary Operator: The ternary operator is an operator that takes three arguments. The first argument is a comparison argument, the second is the result upon a true comparison, and the third is the result upon a false comparison.It is commonly referred to as Conditional Operator.

In computer programming, ?: is a ternary operator that is part of the syntax for a basic conditional expression in several programming languages. Syntax: expression 1 ? expression 2 : expression 3


13. Write a program to find smallest number among four numbers by using ternary operator.
# include # include main( ) { int a,b,c,d,small; printf("Enter value a: "); scanf("%d",&a); printf("Enter the value of b: "); scanf("%d",&b); printf("Enter the value of c: "); scanf("%d",&c); printf("Enter the value of d: "); scanf("%d",&d); small=(a printf("Smallest of the given 4 numbers is: %d",small);getch();}Sample output:Enter value a: 5Enter the value of b: 7Enter the value of c: 3Enter the value of d: 9Smallest of the given 4 numbers is: 3

14. Write a program to find largest element using dynamic memory allocation.
#include #include #include int main() { int i,n; float *data; printf("Enter total number of elements(1 to 100): "); scanf("%d",&n); data=(float*)calloc(n,sizeof(float)); if(data==NULL) { printf("Error!!! memory not allocated."); exit(0); } printf("\n"); for(i=0;i { printf("Enter Number %d: ",i+1); scanf("%f",data+i); } for(i=1;i { if(*data<*(data+i)) *data=*(data+i); } printf("Largest element = %.2f",*data); return 0; getch(); } Sample output: Enter total number of elements (1 to 100): 10 Enter Number 1: 5 Enter Number 2: 8 Enter Number 3: 6.2 Enter Number 4: 5.4 Enter Number 5: 30 Enter Number 6: -7 Enter Number 7: -56 Enter Number 8: 53 Enter Number 9: 56 Enter Number 10: 34 Largest element = 56.00 Dynamic Memory Allocation: The exact size of array is unknown untill the compile time,i.e., time when a compier compiles code written in a programming language into a executable form. The size of array you have declared initially can be sometimes insufficient and sometimes more than required. Dynamic memory allocation allows a program to obtain more memory space, while running or to release space when no space is required.
Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «100+ Most Important C Programs with Output: for Students & Teachers»

Look at similar books to 100+ Most Important C Programs with Output: for Students & Teachers. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «100+ Most Important C Programs with Output: for Students & Teachers»

Discussion, reviews of the book 100+ Most Important C Programs with Output: for Students & Teachers and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.