Showing posts with label numbers. Show all posts
Showing posts with label numbers. Show all posts
Monday, 31 March 2014
C program | To generate random numbers
C program | To generate random numbers
Source code:-)
#include <stdio.h>
#include <stdlib.h>
int main() {
int c, n;
printf("Ten random numbers in [1,100]\n");
for (c = 1; c <= 10; c++) {
n = rand()%100 + 1;
printf("%d\n", n);
}
return 0;
}
C programs | Swapping of two numbers without third(temp) variable in C
C programs | Swapping of two numbers without third(temp) variable in C
Source Code:-)
#include <stdio.h>
int main()
{
int a, b;
printf("Enter two integers to swap\n");
scanf("%d%d", &a, &b);
a = a + b;
b = a - b;
a = a - b;
printf("a = %d\nb = %d\n",a,b);
return 0;
}
C Programs | Swapping of two numbers in c
C programs | Swapping of two numbers in c
Source code:-)
#include <stdio.h>
int main()
{
int x, y, temp;
printf("Enter the value of x and y\n");
scanf("%d%d", &x, &y);
printf("Before Swapping\nx = %d\ny = %d\n",x,y);
temp = x;
x = y;
y = temp;
printf("After Swapping\nx = %d\ny = %d\n",x,y);
return 0;
}
Output:-)
Enter the value of x and y
3
6
Before swapping
x=3
y=6
After swapping
x=6
y=3
Subscribe to:
Posts (Atom)