Program to Reverse an Integer

#include<stdio.h> // Reverse an Integer int main() { int num,rev =0, r; printf(“Enter any number “); scanf(“%d”,& num); while(num>0) { r = num % 10; rev = rev * 10 + r; num = num /10; } printf(“\n\nReverse = %d”, rev); return 0; }

Fibonacci Series up to n number of terms

#include <stdio.h> int main() { int i, n, n1 = 0, n2 = 1, sum = 0; printf(“Enter the number of terms: “); scanf(“%d”,&n); printf(“\n\nFibonacci Series: “); printf(“%d\t%d\t”,n1,n2); for (i = 1; i <= n; i++) { sum = n1+ n2; printf(“%d\t”,sum); n1= n2; n2= sum; } return 0; }

Factorial of a Number

#include<stdio.h> //factorial int main() { int n, fact = 1,i; //for printf(“Using FOR Loop”); printf(“\nPlease Enter number “); scanf(“%d”,&n); if(n<0) { printf(“invalid number”); } else{ for(i=1;i<=n;i++) fact *= i; printf(“\n\nFactorial = %d\n\n”, fact); } return 0; }

Program to Sum the Inputs Until User Enters a Positive Integer

#include<stdio.h> // Program to Sum the Inputs Until User Enters a Positive Integer int main() { int n=0, sum=0; // for printf(“Using For loop\n”); printf(“Enter any positive number “); for(;n>=0;) { sum += n; scanf(“%d”,&n); } printf(“Sum = %d”, sum); //while printf(“\n\nUsing While loop\n”); printf(“Enter any positive number “); n=0; sum=0; while(n>=0) { sum +=…

Sum of numbers entered by a user(using for and while)

#include<stdio.h> // Sum of nums entered by a user int main() { int n, num, sum=0,i; printf(“Enter how many numbers you want to enter “); scanf(“%d”,&n); printf(“Using for loop\n”); for(i=1;i<=n;i++) { printf(“Enter the number “); scanf(“%d”,&num); sum= sum + num; } printf(“\nSum of %d numbers is %d\n\n”,n,sum); printf(“Using while loop\n”); i= 1; while(i<=n) { printf(“Enter…

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 number of rows:…

int and char

The char keyword declares a character variable. Variables of type char are 1 byte in length. They can be signed or unsigned, which means they have a range of -128 to 127 and 0 to 255, respectively.  For example: char alphabet; Variables of type int are one machine-type word in length. They can be signed…

switch, case and default

Branches control switch causes control to branch to one of a list of possible statements in the block of statements. The syntax is switch (expression) statement case constant-expression : where constant-expression must be an int and must be unique. Once a value is computed for expression, the list of possible constant-expression values determined from all case statements is searched for a…

break (c Language)

Passes control out of the compound statement. It makes program jump out of the innermost enclosing loop (while, do, for or switch statements) explicitly. #include<stdio.h> int main() { int input; printf(“Input numbers  –  Input 0 to stop the loop.\n”); for(;;)  // infinite loop { scanf(“%d”, &input); if(input == 0) break; printf(“You have Entered – %d\n”,…

Auto

The auto keyword is a declaration specifies which defines a local variable as having a local lifetime. This is default storage class. All variables declared are of type Auto by default.In order to Explicit declaration of variable use ‘auto’ keyword auto int a = 10;  Storage Memory  Default initial Value Garbage  Scope Local / Block Scope  Life…

Keywords in C Programming Language :

Keywords are predefined, reserved words used in programming that have a special meaning. Keywords are part of the syntax and they cannot be used as an identifier. auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile…