1. Question:Write a scanf function in c programming language which accept paragraph from users 

    Answer
    #include<stdio.h>
    #define MAX 500
    
    int main(){
    
        char arr[MAX];
    
        printf("Enter any paragraph which can include spaces or new line.\n");
        printf("To exit press the tab key.\n");
        scanf("%[^\t]s",arr);
    
        printf("You had entered: \n");
        printf("%s",arr);
    
        return 0;
    }
    Sample output: Enter any paragraph which can include spaces or new line. To exit, press the tab key. C is powerful language. I am learning c from cquestionbank.blogspot.com You had entered: C is powerful language. I am learning c from cquestionbank.blogspot.com

    1. Report
  2. Question:Print prime numbers between 1-300 using break and continue in c 

    Answer
    #include <math.h>
    #include <stdio.h>
    main(){
      int i, j;
      i = 2;
      while ( i < 300 ){
         j = 2;
         while ( j < sqrt(i) ){
             if ( i % j == 0 )
                break;
             else{
                ++j;
                continue;
             }
          }
          if ( j > sqrt(i) )
                printf("%d\t", i);
          ++i;
      }
      return 0;
    }

    1. Report
  3. Question:Palindrome in c without using string function 

    Answer
    #include<stdio.h>
    
    int main(){
      char str[100];
      int i=0,j=-1,flag=0;
    
      printf("Enter a string: ");
      scanf("%s",str);
    
      while(str[++j]!='\0');
      j--;
    
      while(i<j)
          if(str[i++] != str[j--]){
               flag=1;
               break;
          }
         
    
      if(flag == 0)
          printf("The string is a palindrome");
      else
          printf("The string is not a palindrome");
    
      return 0;
    }

    1. Report
  4. Question:Code to find the ASCII values of given character in c programming language 

    Answer
    #include<stdio.h>
    
    int main(){
      
        char c;
    
        printf("Enter any character: ");
        scanf("%c",&c);
    
        printf("ASCII value of given character: %d",c);
            
        return 0;
    }
    Sample output: Enter any character: a ASCII value of given character: 97

    1. Report
  5. Question:C program to extract last two digits of a given year and print it 

    Answer
    #include<stdio.h>
    int main(){
      int yyyy,yy;
    
      printf("Enter a year in for digits: ");
      scanf("%d",&yyyy);
    
      yy = yyyy % 100;
      printf("Last two digits of year is: %02d",yy);
    
      return 0;
    }
    Sample Output: Enter a year in for digits: 1985 Last two digits of year is: 85

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd