c ProgramsMicrosoft Office Word Document (2)

Post on 08-Oct-2015

6 views 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