Posts

Showing posts from October, 2020

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; }

Nested structure in c

#include <stdio.h> int main(){     struct address{     int hno;     char hname [24];     int pincode;     }; struct student { char name[70]; int age ; int rollno; struct address addr ; }; struct student sumit = { "sumitbohare" , 18, 34, {612, "myhoouse", 455332}};  printf("%s, %d, %d %d %s %d", sumit.name , sumit.age , sumit.rollno, sumit.addr.hno,sumit.addr.hname, sumit.addr.pincode );  return 0; }

structure pointer and arrow ppointer

 /* 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 student { char name[70]; int age ; int rollno; }; struct student sumit = { "sumitbohare" , 18, 34}; struct student *ptr; ptr = &sumit; (*ptr).rollno = 35; //ptr -> rollno = 35;  printf("%s, %d, %d ", sumit.name , sumit.age , sumit.rollno );  return 0; }

defining structure variable in different way

  /*structure is used to store differt types of parameter in a single system of fuction sumit.name is used to point out value at name in parameter sumit*/ #include <stdio.h> int main(){ struct student { char name[70]; int age ; int rollno; } sumit = { "sumitbohare" , 18, 34}, Rohit = {"Rohitparmar", 20 , 31}, Aditya= {"AdityaMalviya" , 19, 10};  printf("%s, %d, %d \n", sumit.name , sumit.age , sumit.rollno );  printf("%s, %d, %d\n ", Rohit.name , Rohit.age , Rohit.rollno );  printf("%s, %d, %d ", Aditya.name , Aditya.age , Aditya.rollno );  return 0; }

Struncture : INTRODUCTION

 /*structure is used to store differt types of parameter in a single system of fuction sumit.name is used to point out value at name in parameter sumit*/ #include <stdio.h> int main(){ struct student { char name[70]; int age ; int rollno; }; struct student sumit = { "sumitbohare" , 18, 34};  printf("%s, %d, %d ", sumit.name , sumit.age , sumit.rollno );  return 0; }

to change specific data using strnset;

 /*strnset  is string set used to change the specific function data by our mention data */ #include <stdio.h> #include <string.h> int main() { char data [] = "rohitparmar"; char *p; printf("data used in fuction is %s \n", data); p = strnset(data , '#',5); printf("data used in fuction afte r strset is %s\n", p );  return 0; }

strset used to change data from another data

 /*strset  is string set used to change the complete function data by our mention data */ #include <stdio.h> #include <string.h> int main() { char data [] = "rohit"; char *p; printf("data used in fuction is %s \n", data); p = strset(data+2 , '#'); printf("data used in fuction after strset is %s\n", p );  return 0; }

strrchr used to find the last location of char in c

 /*strrchr is string character found last time in the function strchr is used to find the character found first time in the function */ #include <stdio.h> #include <string.h> int main() { char c [] = "rohitparmar"; char *p; p = strrchr(c , 'r'); if(p == NULL){     printf("character is not found in the string\n"); }else{ printf("character is %c last at location %p\n", *p , p ); }  return 0; }

strchr used in c

 //strchr is string character . we can check wheather // character present in function or nnot also find the //memory address of char #include <stdio.h> #include <string.h> int main() {     char c []= "rohit parmar";     char *p ;    p = strchr(c , 'z');    printf("%c is present at %p " ,*p , p );  return 0; }

strupr and strlwr

 #include <stdio.h> #include <string.h> int main() { char c []= "rohit parmar12#\n"; strupr(c); printf("%s", c); char d [] = "VISHAL PARMAR"; strlwr(d); printf("%s", d); return 0; }

compare two string using strncmp

 /*  if sanme then 0 and if not same then  non zero*/ #include <stdio.h> #include <string.h> int main() {     printf("Enter your name\n");     char *c[9] ;     scanf("%s" , c);  int result;  result = strncmp(c , "Rohit sharma" , 5);     printf("%d" , result);     return 0; } x

compare two string using strcmp

 /* strncat which is used to add or concat two string it is beneficial becaz we can concat  with our choice  we used 15 so we have enough memory */ #include <stdio.h> #include <string.h> int main() {      char destination [34] = "Rohit ";      char source [] = "Parmar medicaps";            strncat (destination , source , 6);      // strcat (destination , "parmar" , 6);     printf("%s " , destination);     return 0; }

concatination using strncat

 /* strncat which is used to add or concat two string it is beneficial becaz we can concat  with our choice  we used 15 so we have enough memory */ #include <stdio.h> #include <string.h> int main() {      char destination [34] = "Rohit ";      char source [] = "Parmar medicaps";            strncat (destination , source , 6);      // strcat (destination , "parmar" , 6);     printf("%s " , destination);     return 0; }

c string concatination using strcat

/*string concat means strcat which is used to add or concat two string we used 15 so we have enough memory */ #include <stdio.h> #include <string.h> int main() {      char destination [15] = "Rohit ";      char source [12] = "Parmar";            strcat (destination , source);      // strcat (destination , "parmar");     printf("%s %s" , destination , source);     return 0; }

string copy strcpy 👇

 //this string copy strcpy is used to copy string value from one variable to another variable // strcpy in costack we first use the target where to copy then source from where to copy #include <stdio.h> #include <string.h> int main() { char source[] = "Rohit Parmar"; char target[30] ; strcpy (target , source);     printf("source is %s and target is  %s\n " , source , target);     return 0; } *************†******†★******************* //this string copy strcpy is used to copy string value from one variable to another variable // strcpy in costack we first use the target where to copy then source from where to copy // here p work as target #include <stdio.h> #include <string.h> int main() { char source[] = "Rohit Parmar"; char  target[30] ; char *p; p = strcpy (target , source);     printf("source is %s and target is  %s  and p is %s" , source , target , p);     return 0; }

Find string length using strlen function

 #include <stdio.h> #include <string.h> int main() { char name [] = {"Rohit Parmar"}; unsigned int length;  length = strlen(name); printf("length = %d\n" , length);     return 0; } ************************************** //using string length to pointer  #include <stdio.h> #include <string.h> int main() { int *p = "Rohit Parmar kannod";  //char name [] = {"Rohit Parmar"}; unsigned int length;  //length = strlen(p);  length = strlen("Rohit Parmar Kannod"); printf("length = %d\n" , length);     return 0; }

Array of pointer to string

 //in string %s we are writing names without pointer * because %s give value at funtion #include <stdio.h> int main() {     char *p = "rohit parmar";     char *q = "vishal parmar";          char *names[] = {         p,         q     };     printf("%s\n %s\n " , names[0] , names[1]);     return 0; }

Array of string

 #include <stdio.h> int main() {     char name[] = "rohit";     char name2[] = {'r','a','m' , '\0'};     char names[][15]  = {         "animesh",         "bhanu",         "chintu",         "dheeraj",         "elvish" };     printf("%s is the 1st name\n" , names[0]);     printf("%c is the 2nd charater of  2nd name\n" , names[1][1]);     return 0; } ************** //If we want input from other then #include <stdio.h> int main() {     char name[] = "rohit";     char name2[] = {'r','a','m' , '\0'};     char names[5][15];     int counter;     for (counter =0 ; counter < 5 ; counter++){         printf("enter the name of %d person\n" , counter+1);         scanf("%s", names[counter]);          ...

Array string relation

 // string array character in c #include <stdio.h> int main() {    char name []= "rohit parmar";    char *p = "rohit parmar ";    p = "vishal parmar";     printf("name is %s" , p);     return 0; }

Constant pointer :

 // in these way we can alter the value of x using pointer #include <stdio.h> int main() {    const int x = 22;    int *p ;    p = &x;    *p = 155;          printf("%d is the value of x" , x);     return 0; } *********"""""***********"""""""********* // in these way we can alter the value of  *p using another  pointer q; #include <stdio.h> int main() {    const int x = 22;     const int *p ;     int *q;         p = &x;    //*p = 155;     q = &x;     *q= 200;     printf("%d is the value of x" , x);     return 0; }

Pointer conversion : pointer casting

 #include <stdio.h> int main() {int x = 10; char c = 'A'; int *p; char *q; void *v; p= (int *)&x; q=(char *)&c;     printf("p = %d\n", *p);     printf ("q= %c\n" , *q);     return 0; }

Pointer to function

 #include <stdio.h> void display (int , char); int main() {  void (*p)(int , char); int a = 12;  char b= 'R';    p = display;     printf("address of display fuction is %p\n" , p);    (*p)(a, b);     return 0; } void display (int a , char b){     printf ("a = %d , b= %c\n" , a, b);      printf("welcome to c programming\n");            }

Pass an array of pointer in function

 #include <stdio.h> void display (int *[] , int ); int main()  {int a = 100, b=200, c=300; int *x[3]; x[0] =&a; x[1] = &b; x[2] = &c; display(x , 3);     return 0; }  void display ( int *x[] , int num){  int counter ; for(counter=0 ; counter<num ; counter++){ printf("%p ------>  %d\n" , x[counter] , *(x[counter]));      }  }

Array and pointer relationship

 #include <stdio.h> int main() {int a= 100, b=200, c=300, d=400; int *x[]= { &a,&b,&c , &d}; printf("x[0]=%p -----> &a = %p ------> *x[0]=%d -----> a= %d\n" , x[0], &a, *x[0] ,a); printf("x[1]=%p -----> &b = %p ------> *x[1]=%d -----> b= %d\n" , x[1], &b, *x[1] ,b); printf("x[2]=%p -----> &c = %p ------> *x[2]=%d -----> c=%d\n" , x[2], &c, *x[2] ,c); printf("x[3]=%p -----> &d = %p ------> *x[3]=%d -----> d= %d\n" , x[3], &d, *x[3] ,d);     printf("Hello World");     return 0; }