1. Question:C program to print hello world without using semicolon 

    Answer
    #include<stdio.h>
    void main(){
        if(printf("Hello world")){
        }
    }
    Sample Output: Hello world

    1. Report
  2. Question:C program to print hello world using while loop 

    Answer
    #include<stdio.h>
    void main(){
        while(!printf("Hello world")){
        }
    }
    Sample Output: Hello world

    1. Report
  3. Question:C program to print hello world using switch 

    Answer
    #include<stdio.h>
    void main(){
        switch(printf("Hello world")){
        }
    }
    Sample Output Hello world

    1. Report
  4. Question:How do you write a program which produces its own source code as its output in c language? 

    Answer
    #include<stdio.h>
    
    int main(){
        FILE *fp;
        char c;
    
        fp = fopen(__FILE__,"r");
     
        do{
             c= getc(fp);
             putchar(c);
        }
        while(c!=EOF);
    
        fclose(fp);
       
        return 0;
    }

    1. Report
  5. Question:Write a c program to reverse a given number 

    Answer
    #include<stdio.h>
    int main(){
        int num,r,reverse=0;
    
        printf("Enter any number: ");
        scanf("%d",&num);
    
        while(num){
             r=num%10;
             reverse=reverse*10+r;
             num=num/10;
        }
    
        printf("Reversed of number: %d",reverse);
        return 0;
    }
    Sample output: Enter any number: 12 Reversed of number: 21

    1. Report
  6. Question:Reverse very large or big numbers beyond the range of long int 

    Answer
    #include<stdio.h>
    #define MAX 1000
    
    int main(){
    
        char num[MAX];
        int i=0,j,flag=0;
    
        printf("Enter any positive integer: ");
        scanf("%s",num);
    
        while(num[i]){
             if(num[i] < 48 || num[i] > 57){
                 printf("Invalid integer number");
                 return 0;
             }
             i++;
        }
    
        printf("Reverse: ");
        for(j=i-1;j>=0;j--)
             if(flag==0 &&  num[j] ==48){
             }
             else{
                 printf("%c",num[j]);
                 flag =1;
             }
    
        return 0;
    Sample output: Enter any positive integer: 234561000045645679001237800000000000 Reverse: 8732100976546540000165432

    1. Report
  7. Question:C program to reverse a number using for loop 

    Answer
    #include<stdio.h>
    int main(){
        int num,r,reverse=0;
    
        printf("Enter any number: ");
        scanf("%d",&num);
    
        for(;num!=0;num=num/10){
             r=num%10;
             reverse=reverse*10+r;
        }
    
        printf("Reversed of number: %d",reverse);
        return 0;
    }
    Sample output: Enter any number: 123 Reversed of number: 321

    1. Report
  8. Question:C program to reverse a number using recursion 

    Answer
    #include<stdio.h>
    int main(){
        int num,reverse;
    
        printf("Enter any number: ");
        scanf("%d",&num);
    
        reverse=rev(num);
        printf("Reverse of number: %d",reverse);
        return 0;
    }
    
    int rev(int num){
        static sum,r;
    
        if(num){
             r=num%10;
             sum=sum*10+r;
             rev(num/10);
        }
        else
             return 0;
    
        return sum;
    }
    Sample output: Enter any number: 456 Reverse of number: 654

    1. Report
  9. Question:C program to calculate sum of digits 

    Answer
    #include<stdio.h>
    int main(){
      int num,sum=0,r;
      printf("Enter a number: ");
      scanf("%d",&num);
      while(num){
          r=num%10;
          num=num/10;
          sum=sum+r;
      }
      printf("Sum of digits of number:  %d",sum);
      return 0;
    }
    Sample output: Enter a number: 123 Sum of digits of number: 6

    1. Report
  10. Question:Sum of digits of a number in c using for loop 

    Answer
    #include<stdio.h>
    int main(){
      int num,sum=0,r;
      printf("Enter a number: ");
      scanf("%d",&num);
    
      for(;num!=0;num=num/10){
          r=num%10;
          sum=sum+r;
      }
      printf("Sum of digits of number:  %d",sum);
      return 0;
    }
    Sample output: Enter a number: 567 Sum of digits of number: 18

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