c programsmicrosoft office word document (2)

39
 swap two numbers without using a temporary variable #include <stdio.h> int main() {  int x = 10, y = 5;  // Code to sa! "x" and "y"  x = x y; // x no $ecomes 15  y = x % y; // y $ecomes 10  x = x % y; // x $ecomes 5  !&int'('te& *a!!in + x = -d, y = -d, x, y);  &etu&n 0; write program to perform sum = 1+ (1+2) + (1+2+3) + …. int main(oid) {  int n, sum;  !&int'(nlease ente& a !ostie inte+e& alue); scan'(-d, 2n);  sum = n 3 ( n 1 )/ 4;  !&int'(n-d, sum);  &etu&n 0;  Write a c program to find largest among three numbers using conditional operator #include<stdio.h> int main(){  int a,$,c,$i+;  !&int'(nnte& 6 num$e&s );  scan'(-d -d -d,2a,2$,2c);

Upload: mainak-sasmal

Post on 08-Oct-2015

6 views

Category:

Documents


0 download

DESCRIPTION

c Programs example

TRANSCRIPT

swap two numbers without using a temporary variable#include int main(){int x = 10, y = 5;// Code to swap 'x' and 'y'x = x + y; // x now becomes 15y = x - y; // y becomes 10x = x - y; // x becomes 5printf("After Swapping: x = %d, y = %d", x, y);return 0;}write program to perform sum = 1+ (1+2) + (1+2+3) +.int main(void){ int n, sum;

printf("\nPlease enter a postive integer value"); scanf("%d", &n); sum = n * ( n + 1 )/ 2; printf("\n%d", sum); return 0;}

Write a c program to find largest among three numbers using conditional operator

#includeint main(){ int a,b,c,big; printf("\nEnter 3 numbers:"); scanf("%d %d %d",&a,&b,&c); big=(a>b&&a>c?a:b>c?b:c); printf("\nThe biggest number is: %d",big); return 0;}

include#includevoid main(){int n1,n2,n3,small;clrscr();printf("Enter three numbers");scanf("%d%d%d",&n1,&n2,&n3);small=n1