Posts

Showing posts from September, 2018

Basic program #2

Image
2. Read any number and find factorial of a number. (Using Loop) #include <stdio.h> int main() {     int n, i;     unsigned long long factorial = 1;     printf("Enter an integer to find it's factorial: ");     scanf("%d",&n);      // show error if the user enters a negative integer     if (n < 0)         printf("Error! Factorial of a negative number doesn't exist.");     else     {            i=1;         while(i<=n)         {             factorial *= i;              // factorial = factorial*i;             i++; ...

Basic Program #1

Image
1. Read any number and check whether a number is prime or not. #include<stdio.h> void main() {      int i,n,flag=0;      printf("Enter a positive number:\n");      scanf("%d",&n);      for(i=2;i<(n/2);i++)      {           if(n%i==0)           {               flag=1;               break;           }      }     if (n==1)       {          printf("1 is neither a prime nor a composite number.\n");       }     else     {     ...