Posts

Showing posts from July, 2015

Accept Array elements

#include<stdio.h> void main() { int arr[10], i, j, k, size; printf("\nEnter array size : "); scanf("%d", &size); printf("\nAccept Numbers : \n"); for (i = 0; i < size; i++) { printf("Data [%d]: ",i+1); scanf("%d", &arr[i]); } printf("\nThe Array is : "); for (i = 0; i < size; i++) printf("%d ", arr[i]); getch(); } Output   Print   Download Code Output Enter array size : 5 Accept Numbers : Data [1]: 2 Data [2]: 6 Data [3]: 7 Data [4]: 1 Data [5]: 2 The Array is : 2 6 7 1 2

Clear Screen without clrscr() function call

#include<stdio.h> void clearmyscreen(); void main() { printf("Hello"); getch(); clearmyscreen(); printf("World"); getch(); } void clearmyscreen() { system("cls"); } Output   Print   Download Code Output World

Find Perimeter of a Circle. Take the value of the radius from user.

#include<stdio.h> #define pi 3.14 void main() { int r; float p; printf("Enter the value of radius: "); scanf("%d", &r); p=2*pi*r; printf("Perimeter=%f",p); } Output   Print   Download Code Output Enter the value of radius: 9 Perimeter=56.520000

Use Macro to define the value of PI and Find the Perimeter of a Circle

#include<stdio.h> #define pi 3.14 void main() { int r; r=7; printf("Perimeter=%f",2*pi*r); } Output   Print   Download Code Output Perimeter=43.960000

Print Pattern 5 

#include <stdio.h> void main() { int i, j, k; for(i=5;i>=1;i--) { for(k=5;k>=i;k--) { printf(" "); } for(j=1;j<i;j++) { printf("*"); } printf("\n"); } getch(); } Output   Print   Download Code Output **** *** ** *

Print Pattern 4 

#include <stdio.h> void main() { int i, j, k; for(i=5;i>=1;i--) { for(j=1;j<=i;j++) printf("*"); printf("\n"); } getch(); } Output   Print   Download Code Output ***** **** *** ** *

Print Pattern 3 

#include <stdio.h> void main() { int i, j, k; for(i=5;i>=1;i--) { for(j=1;j<i;j++) { printf(" "); } for(k=5;k>=i;k--) { printf("*"); } printf("\n"); } getch(); } Output   Print   Download Code Output * ** *** **** *****

Print Pattern 2 

#include <stdio.h> void main() { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("*"); } printf("\n"); } getch(); } Output   Print   Download Code Output * ** *** **** *****

Print Pattern 1 

#include<stdio.h> int main() { int num,r,c; printf("Enter number of rows/columns: "); scanf("%d",&num); for(r=1; r<=num; r++) { for(c=1; c<=num; c++) printf("* "); printf("\n"); } getch(); return 0; } Output   Print   Download Code Output Enter number of rows/columns: 5 * * * * * * * * * * * * * * * * * * * * * * * * *