Posts

Showing posts from 2016
write a program to read a series of words from a terminal using scanf functionprogram:
main( ) { char word1[40], word2[40], word3[40], word4[40]; printf("Enter text : \n"); scanf("%s %s", word1, word2); scanf("%s", word3); scanf("%s", word4); printf("\n"); printf("word1 = %s\nword2 = %s\n", word1, word2); printf("word3 = %s\nword4 = %s\n", word3, word4); } Output Enter text : Gill Road, Gill Park word1 = Gil…
c program to copy one string to another and count the number of characters copiedprogram: main( ) { char string1[80], string2[80]; int i; printf("Enter a string \n"); printf("?"); scanf("%s", string2); for( i=0 ; string2[i] != '\0'; i++) string1[i] = string2[i]; string1[i] = '\0'; …
Source Code to Calculate Factorial Using RecursionProgram:- #include<stdio.h>int factorial(int n);int main(){int n; printf("Enter an positive integer: "); scanf("%d",&n); printf("Factorial of %d = %ld", n, factorial(n));return0;}int factorial(int n){if(n!=1)return n*factorial(n-1);}Output Enter an positive integer: 8
Factorial of 8  = 40320

Image
W.A.P FOR  USE OF IF - ELSE STATEMENT #include <stdio.h>       
int main()                            /* Most important part of the program!  */ {     int age;                          /* Need a variable... */     printf( "Please enter your age" );  /* Asks for age */     scanf( "%d", &age );                 /* The input is put in age */     if ( age < 100 ) {                  /* If the age is less than 100 */         printf ("You are pretty young!\n" ); /* Just to show you it works... */     }     else if ( age == 100 ) {            /* I use else just to show an example */         printf( "You are old\n" );           }     else {         printf( "You are really old\n" );     /* Executed if no other statement is */     }   return 0; }
FLOW CHART OF IF -ELSE STATEMENT