Posts

Showing posts from August, 2017
Write C code to reverse the contents of the array.For example, [1,2,3,4,5] should become [5,4,3,2,1] : - Ans : #include<stdio.h>   int main() {     int arr[20], limit, i;     printf("Enter Limit:\t");     scanf("%d", &limit);     printf("\nEnter %d Elements in 1-Dimensional Array\n", limit);     for(i = 0; i < limit; i++)     {         scanf("%d", &arr[i]);     }     printf("\nArray Elements\n");     for(i = 0; i < limit; i++)     {         printf("%d\t", arr[i]);     }        printf("\nReverse of Array\n");     for(i = limit - 1; i >= 0; i--)     {         printf("%d\t", arr[i]);     }     printf("\n");     return 0; }
Write a C program that uses functions to perform the following: Addition of Two Matrices Multiplication of Two Matrices a. Addition of Two Matrices Program: #include <stdio.h> #include <conio.h> void main() { int a[3][3], b[3][3], c[3][3], i, j; clrscr(); printf( "Enter the elements of 3*3 matrix a \n" ); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { scanf( "%d" , &a[i][j]); } } printf( "Enter the elements of 3*3 matrix b \n" ); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { scanf( "%d" , &b[i][j]); } } for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { c[i][j] = a[i][j] + b[i][j]; } } printf( "The resultant 3*3 matrix c is \n" ); for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { printf( "%d\t" , c[i][j]); } p
Write a C program to find the GCD (greatest common divisor) of two given integers :- #include <stdio.h> int main () { int n1 , n2 , i , gcd ; printf ( "Enter two integers: " ); scanf ( "%d %d" , & n1 , & n2 ); for ( i = 1 ; i <= n1 && i <= n2 ; ++ i ) { // Checks if i is factor of both integers if ( n1 % i == 0 && n2 % i == 0 ) gcd = i ; } printf ( "G.C.D of %d and %d is %d" , n1 , n2 , gcd ); return 0 ; }
C Program To Print Pascals triangle :- #include <stdio.h> long factorial ( int ); int main () { int i , n , c ; printf ( "How many rows you want to show in pascal triangle?\n" ); scanf ( "%d" ,& n ); for ( i = 0 ; i < n ; i ++ ) { for ( c = 0 ; c <= ( n - i - 2 ) ; c ++ ) printf ( " " ); for ( c = 0 ; c <= i ; c ++ ) printf ( "%ld " , factorial ( i )/( factorial ( c )* factorial ( i - c ))); printf ( "\n" ); } return 0 ; } long factorial ( int n ) { int c ; long result = 1 ; for ( c = 1 ; c <= n ; c ++ ) result = result * c ; return ( result ); }
C Program To Find The Roots Of Quadratic Equation: #include <stdio.h> #include <stdlib.h> #include <math.h> void main() {     float a, b, c, root1, root2;     float realp, imagp, disc;       printf("Enter the values of a, b and c \n");     scanf("%f %f %f", &a, &b, &c);      if (a == 0 || b == 0 || c == 0)     {         printf("Error: Roots cannot be determined \n");         exit(1);     }     else     {         disc = b * b - 4.0 * a * c;         if (disc < 0)         {             printf("Imaginary Roots\n");         }          else if (disc == 0)         {             printf("Roots are real and equal\n");             root1 = -b / (2.0 * a);             root2 = root1;             printf("Root1 = %f\n", root1);             printf("Root2 = %f\n", root2);         }         else if (disc > 0 )         {            
C Program To print Fibonacci Series up to n number of terms #include <stdio.h> int main () { int i , n , t1 = 0 , t2 = 1 , nextTerm ; printf ( "Enter the number of terms: " ); scanf ( "%d" , & n ); printf ( "Fibonacci Series: " ); for ( i = 1 ; i <= n ; ++ i ) { printf ( "%d, " , t1 ); nextTerm = t1 + t2 ; t1 = t2 ; t2 = nextTerm ; } return 0 ; }
To Download Or Read The Environmental Studies Text Book By Anubha Kaushi and CP Kaushik , Click Here This is The Book Preferred as ES text Book For SVU Students. 
C program to find the FACTORIAL Of a Number :- #include<stdio.h> int main() {     int n, i, f = 1 ;     printf("Enter a number : ") ;     scanf("%d", &n) ;     for(i = 1 ; i <= n ; i++)     f = f * i ;     printf("\nFactorial value of %d is : %d", n, f) ;   }
C program To find Sum Of The Given Digits of a Number Program: #include<stdio.h> #include<conio.h> void main() { int n, r, s = 0 ; clrscr() ; printf( "Enter a number : " ) ; scanf( "%d" , &n) ; while(n > 0) { r = n % 10 ; s = s + r ; n = n / 10 ; } printf( "\nThe sum of the digits is : %d" , s) ; getch() ; } Output: Enter a number : 12345 The sum of the digits is : 15
Image
C program To Print All The prime numbers between 1 And N :- Algorithm: Step 1: start Step 2: read n Step 3: initialize i = 1, c = 0 Step 4: if i <= n goto step 5 If not goto step 10 Step 5: initialize j = 1 Step 6: if j <= 1 do as the follow. If no goto step 7 i) if i%j == 0 increment c ii) increment j iii) goto Step 6 Step 7: if c == 2 print i Step 8: increment i Step 9: goto step 4 Step 10: stop Flow Chart :- Input & Output: Prime no. series Enter any number 10 The prime numbers between 1 to 10 2 3 5 7 C source code :- #include<stdio.h> #include<conio.h>     int main(){          int N, i, j, isPrime, n;             printf ( "To print all prime numbers between 1 to N\n" );      printf ( "Enter the value of N\n" );      scanf ( "%d" ,&N);          /* For every number between 2 to N, check      whether it is prime n