Posts

Factors : using C

 #include <stdio.h> int main() {     int number , num, factorial=1;     printf("Enter your number :  ");     scanf("%d", & number);    if(number < 0) {     printf("negative number can't computing ");    } else if (number == 0 || number == 1){    printf(" %d ! = 1", number);    }else if (number > 1){    for (num = number ; num > 1 ; num--){     factorial= factorial*num;    }printf(" %d ! = %d", number,factorial);    } return 0; }

Factorial ! calculation

 #include <stdio.h> int main() {     int number , num, factorial=1;     printf("Enter your number :  ");     scanf("%d", & number);    if(number < 0) {     printf("negative number can't computing ");    } else if (number == 0 || number == 1){    printf(" %d ! = 1", number);    }else if (number > 1){    for (num = number ; num > 1 ; num--){     factorial= factorial*num;    }printf(" %d ! = %d", number,factorial);    } return 0; }

Right angle Floyd's triangle

 #include <stdio.h> int main (){ int totalrow=9, row , colomb; for (row = 1 ; row <= totalrow; row++){     for (colomb =1 ; colomb <= row; colomb++){             //printf("%d ", row);             printf("%d ", colomb);     } printf("\n"); }   return 0;   }

Cross shaped pattern

 #include <stdio.h> int main () { int totalrow=5, row , colomb; char name[77]; printf("Enter your name (max 5 character of name) :  "); gets(name); for (row = 0 ; row < totalrow; row++){     for (colomb =0 ; colomb < totalrow; colomb++){   if ((row == colomb) || ((row+colomb) == (totalrow-1)))             printf("%c", name[colomb]);            // printf("*");              else                 printf(" ");     }             printf("\n");     }   return 0;   }

Pyramid pattern

 #include <stdio.h> int main () { int totalrow, row , space, symbol; printf("Enter the number of row :  "); scanf("%d", &totalrow); for (row = 1 ; row <= totalrow; row++){     for (space =1 ; space <= (totalrow-row); space++){         printf(" ");     }     for(symbol=1; symbol <= ((row*2)-1); symbol++){         printf("*");     } printf("\n"); } return 0 ;}

Right angle triangle pattern

 #include <stdio.h> int main () { int num, row , columb; printf("Enter the number of row :  "); scanf("%d", &num); for (row = 1 ; row <= num; row++){     for (columb =1 ; columb <= row; columb++){         printf("*");     }     printf("\n"); } return 0 ;}

Vowel consonent

// this symbol || is or symbol  #include <stdio.h> #include <stdlib.h> #define SIZE 30 int main (){ char ch; char uppercase , lowercase; printf("Enter an alphabate: "); scanf("%c", &ch); uppercase = ch == ('A' || ch=='E' || ch =='I' || ch == 'O' || ch == 'U'); lowercase = ch == ('a' || ch=='e' || ch =='i' || ch == 'o' || ch == 'u'); if (uppercase || lowercase){ printf("%c is a vowel", ch ); }else{ printf("%c is a consonent" , ch); } return 0 ; }

Perfect int number

 /* stdin is input standard input */ #include <stdio.h> #include <stdlib.h> #define SIZE 30 int main (){ int num, rem, sum=0, counter; printf("plz enter the number \n"); scanf("%d", & num); for(counter =1 ; counter <= ( num/2 ) ; counter++){     rem = num%counter;     if (rem==0){         sum = sum+ counter;     } } if (sum == num){     printf("the number %d is a perfect integer number",num); } else{ printf("the number %d is a not a perfect integer number", num); } return 0 ; }

Toggle the character

 /* stdin is input standard input */ #include <stdio.h> #include <stdlib.h> #define SIZE 30 int main (){ char text[SIZE]; int index; printf("please enter the string Value\n"); fgets(text, SIZE, stdin); printf("enter string is %s \n", text); for(index = 0; text[index] != '\0'; index++) {     if(text[index] >= 'A' && text[index] <= 'Z' )     text[index]=text[index]+32;     else if (text[index] >= 'a' && text[index] <= 'z' )     text[index]=text[index]-32; }printf("string value after toggle is %s\n", text); return 0 ; }

String char separately priny

 /* here gets is string reader like getch */ #include <stdio.h> int main (){     char input [100];     int counter ;     gets(input);     for(counter= 0 ; input[counter] != '\0' ; counter++){         printf("%c\n", input[counter]);     } return 0 ; }

123 = 6

 /* here % is ggiving remainder and / gives us quotient */ #include <stdio.h> int main (){     int num , rem=0, sum=0;     printf("Enter the number that you want to add digits \n");     scanf("%d", & num);     while(num>0){         rem=num % 10;         sum = rem+sum;         num = num/10;     } printf("sum of digit is %d ", sum); return 0 ; }

Area of circle

 //we include header file math for maths tools // M_PI maths pi // area of circle is pi radius square #include <stdio.h> #include <math.h> int main (){     float radius, area; printf("enter the radius of circle\n"); scanf("%f" , & radius); area = M_PI * radius *radius ; printf("area of circle is %f " , area); return 0 ; }

Find the Largest

 #include <stdio.h> int main () { int num1 , num2, num3 , largest; printf("enter the num1\n"); scanf ("%d", &num1); printf("enter the num2\n"); scanf("%d", &num2); printf("enter the num3\n"); scanf("%d", &num3); if (num1 > num2 && num1 > num3)     largest = num1; else if (num2 > num1 && num2 > num3)     largest = num2;     else largest = num3;     printf ( " the largest among the three is %d", largest); return 0 ; }

Swap the number

 #include <stdio.h> int main () { int number1, number2 , temp; printf("enter num1\n"); scanf("%d" , & number1); printf("enter num2\n"); scanf("%d" , & number2); printf("before swape num1 = %d , num2 = %d\n" , number1, number2); temp = number1; number1=number2; number2= temp; printf("after swape num1 = %d , num2 = %d\n" , number1, number2); return 0 ; }

ODD EVEN

 #include <stdio.h> int main () { int number, remainder; printf("please enter a number\n"); scanf("%d" , &number); remainder = number % 2; if (remainder == 0 ){     printf("%d is even number", number);     } else {     printf("%d is odd number", number); } return 0 ; }

Sum of all no using integer array

 #include <stdio.h> int main(){ int numval; printf("plese enter number of value that you want to add\n"); scanf("%d", &numval); int values[numval]; int counter; int value; int result = 0; for (counter = 0 ; counter < numval ; counter++){     printf("please enter value %d \n", counter+1);     scanf("%d", &value);     values[counter] = value; } for (counter = 0 ; counter < numval ; counter++){     result = result + values[counter]; }  printf("total = %d\n" , result); return 0;}

Calculator using c

#include<stdio.h> 2 3 int main (){ 4 5 char operator ; 6 double first , second ; 7 8 printf ( "Enter the Operator ( +, -, *, / ) : " ); 9 scanf ( "%c" , & operator ); 10 11 printf ( "Enter the two Numbers one by one : " ); 12 scanf ( "%lf %lf" , & first , & second ); 13 14 switch ( operator ) 15 { 16 17 case '+' : 18 printf ( "%.2lf + %.2lf = %.2lf" , first , second ,( first + second )); 19 break ; 20 21 case '-' : 22 printf ( "%.2lf - %.2lf = %.2lf" , first , second ,( first - second )); 23 break ; 24 25 case '*' : 26 printf ( "%.2lf * %.2lf = %.2lf" , first , second ,( first * second )); 27 break ; 28 29 case '/' : 30 if ( second != 0.0 ) 31 printf ( "%.2lf / %.2lf = %.2lf" , first ,...

Guess the number

 #include <stdio.h> #include <stdlib.h> #include <time.h> int main(){     int mynum ,usernum;     srand(time(NULL));     mynum = rand()%10;     printf("I have a number in my mind (0-10) ; can you guess it !\n");     while(1){         printf(" Enter your guess ");         scanf("%d",&usernum);     if(usernum == mynum){         printf("you got it!\n");         break;     }else if (mynum < usernum){     printf("you enter %d is greater than my num try again" , usernum );     }else {printf("you enter %d is less than my number try again" , usernum);     }     }  return 0; }

Random Number using c

/*this is  the program like ludo  we use  time because time always change we  divide by 7 bcoz  remminder  is  always  less than 7 we also know dice  has  maximum 6 */ #include <stdio.h> #include <stdlib.h> #include <time.h> int main(){     int number;     srand(time(NULL));     number = rand()%7;   printf("rolling result  %d " , number);  return 0; } **★*********★**********★******* winning game  program using random number /*let assume player play with entry fees 250 and win between 100 to 500 */ #include <stdio.h> #include <stdlib.h> #include <time.h> int main(){     int number;     int upper = 500, lower = 100;     srand(time(NULL));     number = rand() % (upper -lower+1) + lower;    printf ("congratulations\n");   printf("you have WON   %d rupees  " , number);  return 0; }

Self referential structure

 /* we can change the value of variables by using pointer in two different ways first by pointer derefernce line no. 19 and second by line no 21*/ #include <stdio.h> int main(){     struct chapter{     char name [24];     int page;     struct chapter *nextchapter;     }; struct chapter ch1 = {"introduction of programming" , 12, NULL}; struct chapter ch2 = {"loop" , 15 , NULL}; struct chapter ch3 = {"break statement", 8 , NULL}; ch1.nextchapter = &ch2; ch2.nextchapter = &ch3; struct chapter *c = &ch1; while( c != NULL) {      printf("title : %s , pages = %d\n" , (*c).name , (*c).page);      c = (*c).nextchapter; }  return 0; }