Skip to main content

Posts

Showing posts with the label Basic

Print the Multiplication Table

#include<stdio.h> void main() { int x=1,num,res; printf("Enter a Number : "); scanf("%d",&num); while(x<=10) { res=num*x; printf("\n%d x %d = %d",num,x,res); x++; } } Output   Print   Download Code Output Enter a Number : 6 6 x 1 = 6 6 x 2 = 12 6 x 3 = 18 6 x 4 = 24 6 x 5 = 30 6 x 6 = 36 6 x 7 = 42 6 x 8 = 48 6 x 9 = 54 6 x 10 = 60

Find the Greatest of Three Numbers

#include<stdio.h> void main() { int x,y,z; printf("Enter values of x, y and z : "); scanf("%d,%d,%d",&x,&y,&z); if(x>=y && x>=z) printf("\n%d is greatest",x); else if(y>=z) printf("\n%d is greatest",y); else printf("\n%d is greatest",z); } Output   Print   Download Code Output Enter values of x, y and z : 4, 9, 2 9 is greatest

Swap two Numbers

#include<stdio.h> void main() { int x,y,z; printf("Enter Values x and y : "); scanf("%d%d",&x,&y); z=y; y=x; x=z; printf("\nValue of x=%d",x); printf("\nValue of y=%d",y); } Output   Print   Download Code Output Enter Values x and y : 5 4 Value of x= 4 Value of y= 5

Sum of two numbers

#include<stdio.h> void main() { int a,b,sum; printf("Enter Numbers a and b : "); scanf("%d %d",&a,&b); sum=a+b; printf("\n%d + %d = %d",a,b,sum); } Output   Print   Download Code Output Enter Numbers a and b :5 4 5 + 4 = 9

Print "Hello, World!" without semicolon

Solution: 1 #include<stdio.h> void main(){ if(printf("Hello world")){ } } Solution: 2 #include<stdio.h> void main(){ while(!printf("Hello world")){ } } Solution: 3 #include<stdio.h> void main(){ switch(printf("Hello world")){ } } Output   Print   Download Code Output Hello, World!

Accept Name, Age from User and Print them on the Screen

#include<stdio.h> int main() { char nam[20]; int age; printf("Enter Your Name : "); scanf("%s",&nam); printf("Enter Your Age : "); scanf("%d",&age); printf("\nYour Name is %s ",nam); printf("and your age is %d",age); return 0; } Output   Print   Download Code Output Enter Your Name : Sumit Enter Your Age : 21 Your Name is Sumit and your age is 21