1.C Program Without Using Semicolon (At Least Do Addition of Two Numbers)
1.C Program Without Using Semicolon (At Least Do Addition of Two Numbers)
# include<stdio.h>
# include<conio.h>
#include <stdio.h>
/* Left shift the result of logical & gives input a and xor operation of a ^ b gives input b */
int main()
{
unsigned int a,b;
printf("Enter the two numbers: \n");
scanf("%d",&a);
scanf("%d",&b);
printf("Sum is: %d",add(a,b));
getch();
}
3. C program to reversing words ..
INPUT: hi how r u.
OUTPUT: u. r how hi
Method 1: (Non recursive) // can get only one line input string words
/* Reading string from last postion to beginning of last string before whitespace and then store
it.Repeat it until whitespace not found. Use another loop to print first string word at last. */
#include <stdio.h>
#include <conio.h>
#include <string.h>
void print()
{
char str[100],c,*p;
int i;
i=0;
scanf("%s",str);
i=strlen(str);
p=str;
i=strlen(str);
i--;
p=p+i;
c=*p; //pointing to last character of a string in a word
if(c!='.') //To get word upto dot found and then end reading input.
print();
// principle of stack last in first out so print string word in reverse order.
printf(" %s",str);
}
void main()
{
char str,temp;
int i,len;
clrscr();
printf("Enter String : ");
print();
getch();
}
4.Write a program to swap two values of variable say a,b without using any arithmetic
operators,temporary variables or pointers.
#include<stdio.h>
#include<conio.h>
void main()
{
int x=1;
int y=5;
printf(“before swapping”);
printf(“x=%d,y=%d”,x,y);
x=x^y; // logical xor operation to compute x=x+y
y=x^y; // logical xor operation to compute y=x-y
x=x^y; // logical xor operation to compute x=x+y
printf(“after swapping”);
printf(“x=%d,y=%d”,x,y);
getch();
}
Example :
Input:
2 //input a integer for no.of test cases/limits.
1 10 // input two integers for limit1
3 5 // input two integers for limit2
Output:
// printing prime numbers for limit1
2
3
5
7
// printing prime numbers for limit2
3
5
#include <stdio.h>
#include<conio.h>
#include<math.h>
i++;
}
printf("\n");
void main()
{
int n[22],m[21],t,i,j;
clrscr();
printf("Enter no.of test case:");
scanf("%d",&t);
for(i=0;i<t;i++)
{
printf("Enter Limits m and n:");
scanf(" %d %d",&m[i],&n[i]);
}
printf("\nPrime Numbers Are Follwing");
for(i=0;i<t;i++)
prime(m[i],n[i]); // passing ranges m and n for t no.of test cases
getch();