└── cp pratice ├── pratice.c ├── o2.c ├── cahp_4.c ├── chap_4pratice.c ├── sir_pratice.c └── assigment2.c /cp pratice/pratice.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | 5 | int start,s2; 6 | int i; 7 | scanf("%d",&start); 8 | for(i=start;i>0;i--) 9 | { 10 | 11 | printf("%d",i); 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /cp pratice/o2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main(){ 4 | int num,r,sum=0,t; 5 | 6 | printf("Input a number: "); 7 | scanf("%d",&num); 8 | 9 | for(t=num;num!=0;num=num/10){ 10 | r=num % 10; xzz 11 | sum=sum*10+r; 12 | } 13 | printf("The number in reverse order is : %d \n",sum); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /cp pratice/cahp_4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 5 | 6 | int main(int argc, char *argv[]) { 7 | 8 | // WHILE:- 9 | 10 | // int i=0; 11 | // while(i<=20){ 12 | // if(i>=10){ 13 | // printf("The number is %d\n",i); 14 | // } 15 | // i++; 16 | // } 17 | 18 | 19 | // "DO-WHILE" :- 20 | 21 | //int i=44; 22 | //do{ 23 | // printf("The value is %d \n",i); 24 | // i++; 25 | //}while(i<10); 26 | 27 | //int i=1 , num; 28 | //printf("Enter the number:"); 29 | //scanf("%d",&num); 30 | //do{ 31 | // printf("%d\n",i); 32 | // i++; 33 | //}while(i<=num); 34 | 35 | 36 | // "FOR" 37 | //int i , num; 38 | //printf("Enter number :"); 39 | //scanf("%d",&num); 40 | //for(i=num;i;i--){ 41 | // printf("%d\n",i); 42 | //} 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | return 0; 84 | } 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /cp pratice/chap_4pratice.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 5 | 6 | int main(int argc, char *argv[]) { 7 | 8 | //Q.1:- multiplaction table 9 | // int i, num ; 10 | // printf("Enter number :"); 11 | // scanf("%d",&num); 12 | // for(i=1 ; i<=10 ; i++){ 13 | // printf("%d * %d = %d \n",num,i,num*i); 14 | // } 15 | 16 | //Q.2:- multiplaction table of number 10 innreversr order 17 | //int i; 18 | //for(i=10;i;i--){ 19 | // printf("10 * %d = %d\n",i,10*i); 20 | //} 21 | 22 | //Q.3:- sum of 10 natural number by while loop 23 | //int i=1 , sum=0, num=10; 24 | //while(i<=num){ 25 | // sum+=i; 26 | // i++; 27 | //} 28 | // printf("The sum of ten natural number %d",sum); 29 | 30 | // int i , sum=0 , num=10; 31 | // for(i=1 ; i<=num ; i++){ 32 | // sum+=i; // i=1: sum=0+1=1 + i=2: sum=1+1=2 + i=3: sum=2+1=3 + i=4: sum=3+1=4... + i=10 sum9+1=10 33 | // } 34 | // printf("The sum of ten natural numbers %d",sum); 35 | // 36 | //int i=1 , sum=0 , num=10 ; 37 | //do{ 38 | //printf("The sum of ten natural numbers %d",sum); 39 | //sum+=i; 40 | //i++; 41 | //}while(i<=num); 42 | // 43 | 44 | 45 | int i , j; 46 | for(i=5;i<=1;i++){ 47 | for(j=5;j>=i;j--){ 48 | printf("1\t"); 49 | } 50 | printf("\n"); 51 | } 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /cp pratice/sir_pratice.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 5 | int main(int argc, char *argv[]) { 6 | 7 | //Q.1:- 8 | //1 9 | //11 10 | //111 11 | //1111 12 | //11111 13 | 14 | //------------------------------// 15 | 16 | 17 | // int i , j; 18 | // for(i=1;i<=5;i++){ 19 | // for(j=1;j<=i;j++){ 20 | // printf("1"); 21 | // } 22 | // printf("\n"); 23 | //} 24 | 25 | //-------------------------------------------------- 26 | 27 | 28 | 29 | //Q.2:- 30 | //11111 31 | //1111 32 | //111 33 | //11 34 | //1 35 | 36 | // int i , j; 37 | // for(i=5;i>=1;i--){ 38 | // for(j=i;j>=1;j--){ 39 | // printf("1"); 40 | // } 41 | // printf("\n"); 42 | // } 43 | 44 | //------------------------------------------------------------------// 45 | 46 | 47 | //Q.3:- 48 | //numbers 1 to 10 49 | 50 | // int i=0; //-------------------initialization 51 | // while(i<=10){ //--------------------conditionc cheacking 52 | // printf("%d \n",i); //--------------------increment/decrement 53 | // i=i+1; 54 | // } 55 | 56 | //---------------------------------------------------------------------- 57 | 58 | 59 | //Q.4:- 60 | //for this series-----11111111111 61 | 62 | //int i=1; 63 | //while(i<=10){ 64 | // printf("1"); 65 | // i++; 66 | //} 67 | 68 | 69 | //int num ,i; 70 | //printf("Enter number:"); 71 | //scanf("%d",&num); 72 | // 73 | //for (i=2 ; i<=num-1 ; i++){ 74 | // num%i==1; 75 | // break; 76 | // 77 | //if(num==1){ 78 | // printf("%d is prime number",num); 79 | //} 80 | //else{ 81 | // printf("%d is not prime number",num); 82 | //} 83 | 84 | 85 | //Q10: Write a program that takes N as input and prints the numbers from 1 to N and their 86 | //squares and cubes in the following manner. 87 | //Eg. N=10 88 | //Number Square Cube 89 | //1 1 1 90 | //2 4 8 91 | //3 9 81 92 | //... .. ... 93 | //10 100 1000 94 | 95 | int i ,num ; 96 | printf("Enter number:"); 97 | scanf("%d",&num); 98 | for(i=1;i<=num;i++){ 99 | printf("%d \t %d \t %d\n",i,i*i,i*i*i); 100 | } 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | return 0; 137 | } 138 | -------------------------------------------------------------------------------- /cp pratice/assigment2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | 6 | //// Q.1 : multiply two number without using * ? 7 | // 8 | // // without using * multiplaction done by adding first num secound num times 9 | // // e.g:- 4 and 5 are two num so 10 | // //4+4+4+4+4=20 && 4*5=20 11 | // 12 | // 13 | // int x, y ; //declaring two integer variable 14 | // int product = 0; //initializing product to zero 15 | // int i; 16 | // printf("Enter two integers:\n"); 17 | // scanf("%d%d", &x, &y); 18 | // 19 | // if(y<0){ //this is becuase if user give negative num this 'if' make negative to positive. 20 | // y=-y; 21 | // x=-x; 22 | // } 23 | // 24 | // //suppose user give x=4 and y=3 two num 25 | // 26 | // for(i=1;i<=y;i++){ // (i=1;1<=3;1++) 27 | // 28 | // product=product+x; //product=0+4 = 4 then product=4+4=8 then product=8+4=12 && 4*3=12 29 | // } //it print 12 30 | // 31 | // printf("\nProuduct of multiplying two numbers are = %d\n", product); 32 | // 33 | // 34 | // 35 | // 36 | //// -------- *-----------------------*---------------------- 37 | // 38 | // 39 | // 40 | ////Q.9:- Write a program to find the letter grade when the score is entered by the user 41 | ////such that if the score is: 42 | ////90 OR ABOVE, grade = A 43 | ////80-89, grade = B 44 | ////70-79, grade = C 45 | ////60-69, grade = D 46 | ////50-59, grade = E 47 | ////BELOW 50, grade = Fail 48 | // 49 | //int sub1 , sub2 , sub3 , sub4 , sub5; 50 | //const int total_marks=500; 51 | //int obtain_marks; 52 | //float precentage; 53 | // 54 | //printf("Enter marks of sbu1="); 55 | //scanf("%d", &sub1); 56 | // 57 | //printf("Enter marks of sbu2="); 58 | //scanf("%d", &sub2); 59 | // 60 | //printf("Enter marks of sbu3="); 61 | //scanf("%d", &sub3); 62 | // 63 | //printf("Enter marks of sbu4="); 64 | //scanf("%d",&sub4); 65 | // 66 | //printf("Enter marks of sbu5="); 67 | //scanf("%d",&sub5); 68 | // 69 | // 70 | //obtain_marks= sub1 + sub2 + sub3 + sub4 + sub5 ; 71 | // 72 | //precentage=(obtain_marks*100)/total_marks; 73 | // 74 | //printf("The precentage is %f \n",precentage); 75 | // 76 | // if(precentage>=90){ 77 | // printf("A\n"); 78 | //} 79 | //else if(precentage>=80 || precentage<90){ 80 | // printf("B\n"); 81 | //} 82 | // else if(precentage>=70 || precentage<=79){ 83 | // printf("C\n"); 84 | //} 85 | //else if(precentage>=60 || precentage<=69){ 86 | // printf("D\n"); 87 | //} 88 | //else { 89 | // printf("Fail\n"); 90 | //} 91 | // 92 | // 93 | //// / -------- *-----------------------*---------------------- 94 | // 95 | //// Q.2:- Design a Case structure program for: 96 | ////a) Even or Not 97 | ////b) Prime or not 98 | ////c) Square or not 99 | ////d) default 100 | // 101 | // 102 | // 103 | //int num , i , square ; 104 | //char choise [10]; 105 | //printf("Enter number"); 106 | //scanf("%d",&num); 107 | //printf("Enter e for even, \n p for prime, \n s for perfect square, \n choise= \t "); 108 | //scanf("%s",&choise); 109 | // 110 | //swtich(choise){ 111 | // case'e': 112 | // case'E': 113 | // if(num%2==0){ 114 | // printf("%d is even.",num); 115 | // } 116 | // else{ 117 | // printf("%d is not even",num); 118 | // } 119 | // 120 | // case'p': 121 | // case'P': 122 | // for(i=2;i<=num-1;i++){ 123 | // if(num%i==0){ 124 | // printf("%d is prime",num); 125 | // } 126 | // else{ 127 | // printf("%d is not prime",num); 128 | // } 129 | // } 130 | // case 's': 131 | // case 'S': 132 | // square=sqrt(num); 133 | // result=(square*square); 134 | // if(result==num){ 135 | // printf("%d is square",num); 136 | // } 137 | // else{ 138 | // printf("%d is not square",num); 139 | // } 140 | // 141 | // 142 | //} 143 | // 144 | // 145 | //// -------- *-----------------------*---------------------- 146 | // 147 | // 148 | ////Q.3:-Write a program to print all multiples of 5 between 1 and 100 (including both 1 and 100). 149 | // 150 | // 151 | //int i; 152 | //printf("The all multiples of 5 between 1 and 100 are: \n"); 153 | //for(i=1;i<=100;i++){ // it start from 1 till 100 154 | // if(i%5==0) // all num which divde from 5 and give reminder 0 are the multiples 155 | // printf("%d,",i); //5%5==0 ,10%5==5,...100%5==0 156 | //} 157 | // 158 | //// -------- *-----------------------*---------------------- 159 | // 160 | ////Q.4:Write a program that will count all the even numbers up to a user-defined stopping point. 161 | // 162 | //int num , i; 163 | //printf("Enter the number for your range is :"); 164 | //scanf("%d",&num); //if num==4:- 165 | //for(i=1;i<=num;i++){ //2%2==0 , 4%2==0 6%2==0 it print 2,4,6. 166 | // if(i%2==0) //but 3%2==not 0 5%2==not 0 so odd num is not print. 167 | // printf("%d,",i); 168 | //} 169 | // 170 | //// -------- *-----------------------*---------------------- 171 | // 172 | ////Q5: Write a program that will perform the following. 173 | ////a) Read in 5 separate numbers. 174 | ////b) Calculate the average of the five numbers. 175 | ////c) Find the smallest (minimum) and largest (maximum) of the five entered numbers. 176 | ////d) Write out the results found from steps b and c with a message describing what they are 177 | // 178 | // 179 | //int i , average, num_1 ,num_2, num_3 , num_4 ,num_5; 180 | //printf("Enter five numbers ="); 181 | //scanf("%d%d%d%d%d",&num_1,&num_2,&num_3,&num_4,&num_5); //suppose 5 num are 2 3 4 6 7 182 | // 183 | //// Finding average 184 | // 185 | //average=(num_1 + num_2 + num_3 + num_4 + num_5) / 5; //(2+3+4+6+7)/5 = 5. 186 | //printf("The average of your five number is %d\n",average); 187 | // 188 | //// Finding maximun 189 | // 190 | //if(num_1>num_2 && num_1>num_3 && num_1>num_4 && num_1>num_5){ //2>3 , 2>4 , 2>6 , 2>7. 191 | // printf("%d is maximum number\n",num_1); 192 | //} 193 | //else if(num_2>num_1 && num_2>num_3 && num_2>num_4 && num_2>num_5){ //3>2 , 3>4 , 3>6 , 3>7. 194 | // printf("%d is maximum number\n",num_2); 195 | //} 196 | //else if(num_3>num_1 && num_3>num_2 && num_3>num_4 && num_3>num_5){ //4>3 , 4>2 , 4>6 , 4>7. 197 | // printf("%d is maximum number\n",num_3); 198 | //} 199 | //else if(num_4>num_1 && num_4>num_3 && num_4>num_2 && num_4>num_5){ //6>3 , 6>4 , 6>2 , 6>7. 200 | // printf("%d is maximum number\n",num_4); 201 | //} 202 | //else if(num_5>num_1 && num_5>num_3 && num_5>num_4 && num_5>num_2){ //7>3 , 7>4 , 7>2 , 7>6. (TRUE) 203 | // printf("%d is maximum number\n",num_5); // 7 is the maximum number. 204 | //} 205 | //else{ 206 | // printf("error"); 207 | //} 208 | // 209 | //// Finding minimun 210 | // 211 | //if(num_1num_1 && num_5>num_3 && num_5>num_4 && num_5>num_2){ //7<3 , 7<4 , 7<6 , 7<2. 224 | // printf("%d is minimum number \n",num_5); 225 | //} 226 | //// -------- *-----------------------*---------------------- 227 | // 228 | // 229 | // 230 | // 231 | // 232 | // 233 | // 234 | // 235 | // 236 | // 237 | // 238 | // 239 | // 240 | // 241 | // 242 | // 243 | // 244 | // 245 | // 246 | // 247 | // 248 | // 249 | // 250 | // 251 | // 252 | // 253 | // 254 | // 255 | // 256 | // 257 | //// -------- *-----------------------*---------------------- 258 | ////Q10: Write a program that takes N as input and prints the numbers from 1 to N and their 259 | ////squares and cubes in the following manner. 260 | ////Eg. N=10 261 | ////Number Square Cube 262 | ////1 1 1 263 | ////2 4 8 264 | ////3 9 81 265 | ////... .. ... 266 | ////10 100 1000 267 | // 268 | //int i ,num ; 269 | //printf("Enter number:"); 270 | //scanf("%d",&num); //4 271 | //for(i=1;i<=num;i++){ //(i=1;1<=4;1++) 272 | // printf("%d \t %d \t %d\n",i,i*i,i*i*i); // i=1: 1 1*1 1*1*1 ---------------- 1 1 1 273 | //} //i=2: 2 2*2 2*2*2-----------------2 4 8 274 | 275 | 276 | 277 | ///======================================= 278 | 279 | //int x, sum; 280 | //sum = 0; 281 | //printf("Enter number:"); 282 | //scanf("%d",&x); 283 | //while(x <= 0) 284 | //{ sum = sum + x; 285 | // printf("%d",x); 286 | //} 287 | 288 | 289 | //o ,'' 290 | 291 | 292 | ////----------Fibonacci Series----------------- 293 | // int i, n; 294 | // 295 | // // initialize first and second terms 296 | // 297 | // int t1 = 0, t2 = 1; 298 | // 299 | // // initialize the next term (3rd term) 300 | // 301 | // int nextTerm = t1 + t2; 302 | // 303 | // // get no. of terms from user 304 | // 305 | // printf("Enter the number of terms: "); 306 | // scanf("%d", &n); 307 | // 308 | // // print the first two terms t1 and t2 309 | // 310 | // printf("Fibonacci Series: %d, %d, ", t1, t2); 311 | // 312 | // // print 3rd to nth terms 313 | // 314 | // for (i = 3; i <= n; ++i) { 315 | // printf("%d, ", nextTerm); 316 | // t1 = t2; 317 | // t2 = nextTerm; 318 | // nextTerm = t1 + t2; 319 | // } 320 | 321 | 322 | //============================================================================ 323 | 324 | 325 | //// TO CHEAK AMSTRONG SEIRES; 326 | 327 | // int num, Num, remainder, result = 0; 328 | // printf("Enter a three-digit integer: "); 329 | // scanf("%d", &num); 330 | // Num = num; 331 | // 332 | // while (Num != 0) { 333 | // // remainder contains the last digit 334 | // 335 | // remainder = Num % 10; 336 | // 337 | // result += remainder * remainder * remainder; 338 | // 339 | // // removing last digit from the orignal number 340 | // 341 | // Num /= 10; 342 | // } 343 | // 344 | // if (result == num) 345 | // printf("%d is an Armstrong number.", num); 346 | // else 347 | // printf("%d is not an Armstrong number.", num); 348 | 349 | 350 | //===================================================== 351 | 352 | 353 | //AMSTRONG SEIRES 1 FROM 1000. 354 | 355 | // int i , x , reminder ,sum; 356 | //printf("AMSTRONG SEIRES 1 FROM 1000.\n"); 357 | //for(i=1;i<=1000;i++){ 358 | // sum=0; 359 | // x=i; 360 | // while(x!=0){ 361 | // reminder=x%10; 362 | // sum+=(reminder*reminder*reminder); 363 | // x=x/10; 364 | // } 365 | // if(sum==i) 366 | // printf("%d ,",i); 367 | //} 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | //int i ,j , num; 376 | //printf("Enter number"); 377 | //scanf("%d",&num); 378 | //for(i=1;i<=num;i++){ 379 | // for(j=i;j>=1;j--){ 380 | // printf("%d",j%2); 381 | // } 382 | // 383 | // printf("\n"); 384 | //} 385 | 386 | 387 | 388 | 389 | //int i ,j , space ,row ,k ; 390 | //printf("Enter number = "); 391 | //scanf("%d",&row); 392 | //space=row+4-1; 393 | //for(i=1;i<=row;i++){ 394 | // for(k=space;k>=1;k--){ 395 | // printf(" "); 396 | // } 397 | // for(j=1;j<=i;j++){ 398 | // printf("* "); 399 | // } 400 | // printf("\n"); 401 | // space--; 402 | // 403 | // } 404 | 405 | // int i,j,spc,rows,k; 406 | // printf("Input number of rows : "); 407 | // scanf("%d",&rows); 408 | // spc=rows+4-1; 409 | // for(i=1;i<=rows;i++) 410 | // { 411 | // for(k=spc;k>=1;k--){ 412 | // printf(" "); 413 | // } 414 | // for(j=1;j<=i;j++){ 415 | // printf("* "); 416 | // } 417 | // printf("\n"); 418 | // spc--; 419 | // } 420 | 421 | 422 | 423 | 424 | // int i,j,n; 425 | // printf("Input number of rows for this pattern :"); 426 | // scanf("%d",&n); 427 | // for(i=0;i=1;i--){ 449 | // for(j=1;j<=n-i;j++){ 450 | // printf(" "); 451 | // } 452 | // for(j=1;j<=2*i-1;j++){ 453 | // printf("*"); 454 | // } 455 | // printf("\n"); 456 | //} 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | //int i ,j ; 486 | //for(i=1;i<=5;i++){ //i=1 & j=1 it print:1 487 | // for(j=1;j<=i;j++){ //i=2 & j=1 ,j=2 it print:1 2 488 | // printf("%d",j); //i=2 & j=1 ,j=2, j=3 it print:1 2 3 489 | // } //i=2 & j=1 ,j=2 ,j=3 ,j=4 it print:1 2 3 4 490 | // printf("\n"); //i=2 & j=1 ,j=2 ,j=3 ,j=4, j=5 it print:1 2 3 4 5 491 | //} 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | //int i , j; 500 | //for(i=5;i>=1;i--){ //i=5 & j=1 ,j=2, j=3, j=4 ,j=5 it print 1 2 3 4 5 501 | // for(j=1;j<=i;j++){ //i=4 & j=1 ,j=2, j=3, j=4 it print 1 2 3 4 502 | // printf("%d \t",j); //i=3 & j=1 ,j=2, j=3 it print 1 2 3 503 | // } //i=2 & j=1 ,j=2, it print 1 2 504 | // printf("\n"); //i=2 & j=1 ,j=2, it print 1 505 | //} 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | return 0; 533 | } 534 | --------------------------------------------------------------------------------