Showing posts with label w3. Show all posts
Showing posts with label w3. Show all posts
Monday, 31 March 2014
C Programs | ShutDown computer | code for Ubuntu Linux
C Programs | ShutDown computer | code for Ubuntu Linux
Source code:-)
#include <stdio.h>
int main() {
system("shutdown -P now");
return 0;
}
C Programs | ShutDown computer | code for Windows xp
C Programs | C programming code for Windows xp
Source code:-)
#include <stdio.h>
#include <stdlib.h>
main()
{
char ch;
printf("Do you want to shutdown your computer now (y/n)\n");
scanf("%c",&ch);
if (ch == 'y' || ch == 'Y')
system("C:\\WINDOWS\\System32\\shutdown -s");
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
C program | To Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch.....case
C program | To Make a Simple Calculator to Add, Subtract, Multiply or Divide Using switch.....case
Source code :-)
/* C programming-Source code to create a simple calculator for addition, subtraction, multiplication and division using switch...case statement */
# include <stdio.h>
int main()
{
char o;
float num1,num2;
printf("Enter operator either + or - or * or divide : ");
scanf("%c",&o);
printf("Enter two operands: ");
scanf("%f%f",&num1,&num2);
switch(o) {
case '+':
printf("%.1f + %.1f = %.1f",num1, num2, num1+num2);
break;
case '-':
printf("%.1f - %.1f = %.1f",num1, num2, num1-num2);
break;
case '*':
printf("%.1f * %.1f = %.1f",num1, num2, num1*num2);
break;
case '/':
printf("%.1f / %.1f = %.1f",num1, num2, num1/num2);
break;
default:
/* If operator is other than +, -, * or /, error message is shown */
printf("Error! operator is not correct");
break;
}
return 0;
Output:-)
Enter operator either + or - or * or divide : -
Enter two operands: 3.4
8.4
3.4 - 8.4 = -5.0
C Program | To Find ASCII Value of a Character-Source code
C Program | To Find ASCII Value of a Character
Source code:-)
/* Source code to find ASCII value of a character entered by user */
#include <stdio.h>
int main(){
char c;
printf("Enter a character: ");
scanf("%c",&c); /* Takes a character from user */
printf("ASCII value of %c = %d",c,c);
return 0;
}
Output:-)
Enter a character: G
ASCII value of G = 71
C Program-Find Size of int, float, double and char of System-Syntax-Source Code-Output
C Program-Find Size of int, float, double and char of System
Syntax of size of Operator:-
temp = sizeof(operand);
/* Here, temp is a variable of type integer,i.e, sizeof() operator
returns integer value. */
Source Code :-)
/* This program computes the size of variable using sizeof operator.*/
#include <stdio.h>
int main()
{
int a;
float b;
double c;
char d;
printf("Size of int: %d bytes\n",sizeof(a));
printf("Size of float: %d bytes\n",sizeof(b));
printf("Size of double: %d bytes\n",sizeof(c));
printf("Size of char: %d byte\n",sizeof(d));
return 0;
}
OUTPUT :-)
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte
Subscribe to:
Posts (Atom)